mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-15 02:12:29 +12:00
Adds "Sentence mode" to Focus mode. #259
This commit is contained in:
parent
19f8938852
commit
3c140d755f
|
@ -75,7 +75,7 @@ textEditor = {
|
|||
"marginsTB": 20,
|
||||
"backgroundTransparent": False,
|
||||
"alwaysCenter": False,
|
||||
"focusMode": False # "line", "paragraph"
|
||||
"focusMode": False # "line", "paragraph", "sentence"
|
||||
}
|
||||
|
||||
revisions = {
|
||||
|
|
|
@ -206,8 +206,9 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
self.chkEditorTypeWriterMode.stateChanged.connect(self.updateEditorSettings)
|
||||
self.cmbEditorFocusMode.setCurrentIndex(
|
||||
0 if not opt["focusMode"] else
|
||||
1 if opt["focusMode"] == "line" else
|
||||
2)
|
||||
1 if opt["focusMode"] == "sentence" else
|
||||
2 if opt["focusMode"] == "line" else
|
||||
3)
|
||||
self.cmbEditorFocusMode.currentIndexChanged.connect(self.updateEditorSettings)
|
||||
# Text areas
|
||||
self.chkEditorMaxWidth.setChecked(opt["maxWidth"] != 0)
|
||||
|
@ -504,7 +505,8 @@ class settingsWindow(QWidget, Ui_Settings):
|
|||
settings.textEditor["alwaysCenter"] = self.chkEditorTypeWriterMode.isChecked()
|
||||
settings.textEditor["focusMode"] = \
|
||||
False if self.cmbEditorFocusMode.currentIndex() == 0 else \
|
||||
"line" if self.cmbEditorFocusMode.currentIndex() == 1 else \
|
||||
"sentence" if self.cmbEditorFocusMode.currentIndex() == 1 else \
|
||||
"line" if self.cmbEditorFocusMode.currentIndex() == 2 else \
|
||||
"paragraph"
|
||||
|
||||
# Text area
|
||||
|
|
|
@ -95,6 +95,7 @@ class MarkdownHighlighter(BasicHighlighter):
|
|||
if settings.textEditor["focusMode"] == "paragraph":
|
||||
return not self.currentBlock().contains(
|
||||
self.editor.textCursor().position())
|
||||
|
||||
elif settings.textEditor["focusMode"] == "line":
|
||||
if self.currentBlock().contains(
|
||||
self.editor.textCursor().position()):
|
||||
|
@ -109,6 +110,28 @@ class MarkdownHighlighter(BasicHighlighter):
|
|||
return (start, end)
|
||||
else:
|
||||
return True
|
||||
|
||||
elif settings.textEditor["focusMode"] == "sentence":
|
||||
if self.currentBlock().contains(
|
||||
self.editor.textCursor().position()):
|
||||
block = self.currentBlock()
|
||||
# Position of cursor in block
|
||||
pos = self.editor.textCursor().position() - block.position()
|
||||
ENDChars = "!.?"
|
||||
txt = block.text()
|
||||
start = -1
|
||||
for i in range(len(txt)):
|
||||
if start == -1: start = i
|
||||
if txt[i] in ENDChars:
|
||||
s = txt[start:i+1]
|
||||
if start <= pos <= start + len(s):
|
||||
return start, i+1
|
||||
start = -1
|
||||
return (start, len(txt))
|
||||
|
||||
else:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def doHighlightBlock(self, text):
|
||||
|
|
|
@ -1326,6 +1326,7 @@ class Ui_Settings(object):
|
|||
self.cmbEditorFocusMode.addItem("")
|
||||
self.cmbEditorFocusMode.addItem("")
|
||||
self.cmbEditorFocusMode.addItem("")
|
||||
self.cmbEditorFocusMode.addItem("")
|
||||
self.formLayout_10.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.cmbEditorFocusMode)
|
||||
self.verticalLayout_22.addWidget(self.groupBox_15)
|
||||
self.horizontalLayout_4.addLayout(self.verticalLayout_22)
|
||||
|
@ -2010,8 +2011,9 @@ class Ui_Settings(object):
|
|||
self.chkEditorTypeWriterMode.setText(_translate("Settings", "Typewriter mode"))
|
||||
self.label_52.setText(_translate("Settings", "Focus mode"))
|
||||
self.cmbEditorFocusMode.setItemText(0, _translate("Settings", "None"))
|
||||
self.cmbEditorFocusMode.setItemText(1, _translate("Settings", "Line"))
|
||||
self.cmbEditorFocusMode.setItemText(2, _translate("Settings", "Paragraph"))
|
||||
self.cmbEditorFocusMode.setItemText(1, _translate("Settings", "Sentence"))
|
||||
self.cmbEditorFocusMode.setItemText(2, _translate("Settings", "Line"))
|
||||
self.cmbEditorFocusMode.setItemText(3, _translate("Settings", "Paragraph"))
|
||||
self.tabViews.setTabText(self.tabViews.indexOf(self.tab_4), _translate("Settings", "Text editor"))
|
||||
self.lblTitleLabels.setText(_translate("Settings", "Labels"))
|
||||
self.btnLabelColor.setShortcut(_translate("Settings", "Ctrl+S"))
|
||||
|
|
|
@ -2679,6 +2679,11 @@
|
|||
<string>None</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Sentence</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Line</string>
|
||||
|
|
Loading…
Reference in a new issue