Skip to content

Commit 6901c4b

Browse files
committed
#3690: make highlighting across multiple lines optional
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent e2eb205 commit 6901c4b

8 files changed

Lines changed: 63 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 26.8.12
44

5+
- Added a new editor setting to disable highlighting and applying of Markdown text
6+
formatting across multiple lines; it is enabled by default
7+
(for [#3690](https://github.com/pbek/QOwnNotes/issues/3690))
58
- Whitespace markers in the note editor can now use a separate foreground color
69
configured in the editor color scheme (for [#3670](https://github.com/pbek/QOwnNotes/issues/3670))
710
- Added an **Insert footnote** action to the _Edit_ menu and the note editor context

src/mainwindow.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,9 +6064,16 @@ void MainWindow::applyFormatter(const QString &formatter) {
60646064
c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, formatter.length());
60656065
textEdit->setTextCursor(c);
60666066
} else {
6067+
// Only allow formatting across multiple lines if the feature is enabled
6068+
QRegularExpression::PatternOptions patternOptions =
6069+
SettingsService()
6070+
.value(QStringLiteral("Editor/multilineInlineHighlighting"), true)
6071+
.toBool()
6072+
? QRegularExpression::DotMatchesEverythingOption
6073+
: QRegularExpression::NoPatternOption;
6074+
60676075
QRegularExpressionMatch match =
6068-
QRegularExpression(QStringLiteral(R"(^(\s*)(.+?)(\s*)$)"),
6069-
QRegularExpression::DotMatchesEverythingOption)
6076+
QRegularExpression(QStringLiteral(R"(^(\s*)(.+?)(\s*)$)"), patternOptions)
60706077
.match(selectedText);
60716078
if (match.hasMatch()) {
60726079
QString formattedText =

src/widgets/qownnotesmarkdowntextedit.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,6 +2722,13 @@ void QOwnNotesMarkdownTextEdit::updateSettings() {
27222722

27232723
setHighlightingEnabled(highlightingEnabled);
27242724

2725+
if (_highlighter) {
2726+
// enable or disable highlighting of inline formatting across multiple lines
2727+
_highlighter->setMultilineInlineHighlightingEnabled(
2728+
settings.value(QStringLiteral("Editor/multilineInlineHighlighting"), true)
2729+
.toBool());
2730+
}
2731+
27252732
if (highlightingEnabled) {
27262733
// set the new highlighting styles
27272734
setStyles();

src/widgets/settings/editorsettingswidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ void EditorSettingsWidget::readSettings() {
4949
settings.value(QStringLiteral("markdownHighlightingEnabled"), true).toBool());
5050
ui->fullyHighlightedBlockquotesCheckBox->setChecked(
5151
settings.value(QStringLiteral("fullyHighlightedBlockquotes")).toBool());
52+
ui->multilineInlineHighlightingCheckBox->setChecked(
53+
settings.value(QStringLiteral("Editor/multilineInlineHighlighting"), true).toBool());
54+
// Initialize the enabled state of the highlighting dependent checkboxes
55+
on_markdownHighlightingCheckBox_toggled(ui->markdownHighlightingCheckBox->isChecked());
5256
ui->autoBracketClosingCheckBox->setChecked(
5357
settings.value(QStringLiteral("Editor/autoBracketClosing"), true).toBool());
5458
ui->autoBracketRemovalCheckBox->setChecked(
@@ -105,6 +109,8 @@ void EditorSettingsWidget::storeSettings() {
105109
ui->markdownHighlightingCheckBox->isChecked());
106110
settings.setValue(QStringLiteral("fullyHighlightedBlockquotes"),
107111
ui->fullyHighlightedBlockquotesCheckBox->isChecked());
112+
settings.setValue(QStringLiteral("Editor/multilineInlineHighlighting"),
113+
ui->multilineInlineHighlightingCheckBox->isChecked());
108114
settings.setValue(QStringLiteral("Editor/autoBracketClosing"),
109115
ui->autoBracketClosingCheckBox->isChecked());
110116
settings.setValue(QStringLiteral("Editor/autoBracketRemoval"),
@@ -156,10 +162,11 @@ void EditorSettingsWidget::on_cursorWidthResetButton_clicked() {
156162
}
157163

158164
/**
159-
* Enables or disables the fully highlighted blockquotes checkbox
165+
* Enables or disables the highlighting dependent checkboxes
160166
*/
161167
void EditorSettingsWidget::on_markdownHighlightingCheckBox_toggled(bool checked) {
162168
ui->fullyHighlightedBlockquotesCheckBox->setEnabled(checked);
169+
ui->multilineInlineHighlightingCheckBox->setEnabled(checked);
163170
}
164171

165172
/**

src/widgets/settings/editorsettingswidget.ui

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
<layout class="QGridLayout" name="gridLayout">
1414
<item row="0" column="0">
1515
<widget class="QGroupBox" name="groupBox_17">
16-
<property name="minimumSize">
17-
<size>
18-
<width>0</width>
19-
<height>90</height>
20-
</size>
21-
</property>
2216
<property name="title">
2317
<string>Markdown highlighting</string>
2418
</property>
@@ -40,6 +34,16 @@
4034
</property>
4135
</widget>
4236
</item>
37+
<item row="2" column="1" colspan="2">
38+
<widget class="QCheckBox" name="multilineInlineHighlightingCheckBox">
39+
<property name="toolTip">
40+
<string>Allows emphasis, strong, underline and strikeout formatting to span multiple lines in the note editor</string>
41+
</property>
42+
<property name="text">
43+
<string>Highlight and apply Markdown text formatting across multiple lines</string>
44+
</property>
45+
</widget>
46+
</item>
4347
</layout>
4448
</widget>
4549
</item>

tests/unit_tests/testcases/app/test_qmarkdowntextedit.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ void TestQMarkdownTextEdit::testMultilineInlineHighlighting() {
230230
QVERIFY(formatAt(editor.document()->firstBlock(), 6).fontUnderline());
231231
}
232232

233+
void TestQMarkdownTextEdit::testMultilineInlineHighlightingDisabled() {
234+
QMarkdownTextEdit editor;
235+
editor.highlighter()->setMultilineInlineHighlightingEnabled(false);
236+
237+
editor.setPlainText(QStringLiteral("~~first line\nsecond line\nthird line~~"));
238+
editor.highlighter()->rehighlight();
239+
QVERIFY(!formatAt(editor.document()->findBlockByNumber(1), 0).fontStrikeOut());
240+
QVERIFY(!formatAt(editor.document()->findBlockByNumber(2), 0).fontStrikeOut());
241+
242+
editor.setPlainText(QStringLiteral("**first line\nsecond line**"));
243+
editor.highlighter()->rehighlight();
244+
QVERIFY(formatAt(editor.document()->findBlockByNumber(1), 0).fontWeight() != int(QFont::Bold));
245+
246+
editor.setPlainText(QStringLiteral("*first line\nsecond line\nthird line*"));
247+
editor.highlighter()->rehighlight();
248+
QVERIFY(!formatAt(editor.document()->findBlockByNumber(1), 0).fontItalic());
249+
QVERIFY(!formatAt(editor.document()->findBlockByNumber(2), 0).fontItalic());
250+
251+
// Turning it back on re-enables multi-line highlighting
252+
editor.highlighter()->setMultilineInlineHighlightingEnabled(true);
253+
QVERIFY(formatAt(editor.document()->findBlockByNumber(1), 0).fontItalic());
254+
QVERIFY(formatAt(editor.document()->findBlockByNumber(2), 0).fontItalic());
255+
}
256+
233257
void TestQMarkdownTextEdit::testWhitespaceMarkerHighlighting() {
234258
QCOMPARE(int(MarkdownHighlighter::LinkInternal), 34);
235259
QCOMPARE(int(MarkdownHighlighter::Whitespace), 35);

tests/unit_tests/testcases/app/test_qmarkdowntextedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class TestQMarkdownTextEdit : public QObject {
1717
void testSqlCodeBlockHighlighting();
1818
void testForthCommentHighlighting();
1919
void testMultilineInlineHighlighting();
20+
void testMultilineInlineHighlightingDisabled();
2021
void testWhitespaceMarkerHighlighting();
2122
void testLinkedCheckBoxDetectionInReadOnlyEditor();
2223
void testFootnoteNavigationAndHighlighting();

0 commit comments

Comments
 (0)