Implement a new word auto select feature that is more careful with punctuation
This commit is contained in:
@@ -327,8 +327,7 @@ class nwQuotes:
|
|||||||
|
|
||||||
|
|
||||||
class nwUnicode:
|
class nwUnicode:
|
||||||
"""Supported unicode character constants and their HTML equivalents.
|
"""Supported unicode character constants and their HTML equivalents."""
|
||||||
"""
|
|
||||||
# Unicode Constants
|
# Unicode Constants
|
||||||
# =================
|
# =================
|
||||||
|
|
||||||
|
|||||||
@@ -1934,27 +1934,39 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
|
|
||||||
def _autoSelect(self) -> QTextCursor:
|
def _autoSelect(self) -> QTextCursor:
|
||||||
"""Return a cursor which may or may not have a selection based
|
"""Return a cursor which may or may not have a selection based
|
||||||
on user settings and document action.
|
on user settings and document action. The selection will be the
|
||||||
|
word closest to the cursor consisting of alphanumerical unicode
|
||||||
|
characters.
|
||||||
"""
|
"""
|
||||||
cursor = self.textCursor()
|
cursor = self.textCursor()
|
||||||
if CONFIG.autoSelect and not cursor.hasSelection():
|
if CONFIG.autoSelect and not cursor.hasSelection():
|
||||||
cursor.select(QTextCursor.WordUnderCursor)
|
cPos = cursor.position()
|
||||||
posS = cursor.selectionStart()
|
bPos = cursor.block().position()
|
||||||
posE = cursor.selectionEnd()
|
bLen = cursor.block().length()
|
||||||
|
|
||||||
# Underscore counts as a part of the word, so check that the
|
# Scan backwards
|
||||||
# selection isn't wrapped in italics markers.
|
sPos = cPos
|
||||||
reSelect = False
|
for i in range(cPos - bPos):
|
||||||
if self._qDocument.characterAt(posS) == "_":
|
sPos = cPos - i - 1
|
||||||
posS += 1
|
if not self._qDocument.characterAt(sPos).isalnum():
|
||||||
reSelect = True
|
sPos += 1
|
||||||
if self._qDocument.characterAt(posE) == "_":
|
break
|
||||||
posE -= 1
|
|
||||||
reSelect = True
|
# Scan forwards
|
||||||
if reSelect:
|
ePos = cPos
|
||||||
cursor.clearSelection()
|
for i in range(bPos + bLen - cPos):
|
||||||
cursor.setPosition(posS, QTextCursor.MoveAnchor)
|
ePos = cPos + i
|
||||||
cursor.setPosition(posE-1, QTextCursor.KeepAnchor)
|
if not self._qDocument.characterAt(ePos).isalnum():
|
||||||
|
# ePos -= 1
|
||||||
|
break
|
||||||
|
|
||||||
|
if ePos - sPos <= 0:
|
||||||
|
# No selection possible
|
||||||
|
return cursor
|
||||||
|
|
||||||
|
cursor.clearSelection()
|
||||||
|
cursor.setPosition(sPos, QTextCursor.MoveAnchor)
|
||||||
|
cursor.setPosition(ePos, QTextCursor.KeepAnchor)
|
||||||
|
|
||||||
self.setTextCursor(cursor)
|
self.setTextCursor(cursor)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user