diff --git a/src/dialogs/editconfigwidget.ui b/src/dialogs/editconfigwidget.ui
--- a/src/dialogs/editconfigwidget.ui
+++ b/src/dialogs/editconfigwidget.ui
@@ -6,23 +6,11 @@
0
0
- 459
- 458
+ 545
+ 566
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
+
-
@@ -144,14 +132,60 @@
Auto Brackets
-
+
-
Enable automatic brackets
+ -
+
+
-
+
+
+ WhatsThisCursor
+
+
+
+
+
+ When there is some text selected will theses chars add in a way "Auto Bracket" do
+
+
+ Chars to enclose a selection:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
@@ -192,7 +226,7 @@
- 0
+ 8
1
diff --git a/src/dialogs/katedialogs.cpp b/src/dialogs/katedialogs.cpp
--- a/src/dialogs/katedialogs.cpp
+++ b/src/dialogs/katedialogs.cpp
@@ -463,6 +463,22 @@
observeChanges(ui->chkTextDragAndDrop);
observeChanges(ui->chkSmartCopyCut);
observeChanges(ui->chkStaticWordWrap);
+ observeChanges(ui->cmbEncloseSelection);
+ connect(ui->cmbEncloseSelection->lineEdit(), &QLineEdit::editingFinished, [=] {
+ const int index = ui->cmbEncloseSelection->currentIndex();
+ const QString text = ui->cmbEncloseSelection->currentText();
+ // Text removed? Remove item, but don't remove default data!
+ if (index >= KateViewConfig::UserData && text.isEmpty()) {
+ ui->cmbEncloseSelection->removeItem(index);
+ slotChanged();
+
+ // Not already there? Add new item! For what ever reason isn't it's done automatically
+ } else if (ui->cmbEncloseSelection->findText(text) < 0) {
+ ui->cmbEncloseSelection->addItem(text);
+ slotChanged();
+ }
+ ui->cmbEncloseSelection->setCurrentIndex(ui->cmbEncloseSelection->findText(text));
+ });
observeChanges(ui->cmbInputMode);
observeChanges(ui->sbWordWrap);
@@ -492,6 +508,11 @@
KateRendererConfig::global()->setWordWrapMarker(ui->chkShowStaticWordWrapMarker->isChecked());
KateViewConfig::global()->setValue(KateViewConfig::AutoBrackets, ui->chkAutoBrackets->isChecked());
+ KateViewConfig::global()->setValue(KateViewConfig::CharsToEncloseSelection, ui->cmbEncloseSelection->currentText());
+ QStringList userLetters; for (int i = KateViewConfig::UserData; i < ui->cmbEncloseSelection->count(); ++i) {
+ userLetters.append(ui->cmbEncloseSelection->itemText(i));
+ }
+ KateViewConfig::global()->setValue(KateViewConfig::UserSetsOfCharsToEncloseSelection, userLetters);
KateViewConfig::global()->setValue(KateViewConfig::InputMode, ui->cmbInputMode->currentData().toInt());
KateViewConfig::global()->setValue(KateViewConfig::MousePasteAtCursorPosition, ui->chkMousePasteAtCursorPosition->isChecked());
KateViewConfig::global()->setValue(KateViewConfig::TextDragAndDrop, ui->chkTextDragAndDrop->isChecked());
@@ -513,8 +534,26 @@
ui->sbWordWrap->setSuffix(ki18ncp("Wrap words at (value is at 20 or larger)", " character", " characters"));
ui->sbWordWrap->setValue(KateDocumentConfig::global()->wordWrapAt());
+ ui->cmbEncloseSelection->clear();
+ ui->cmbEncloseSelection->lineEdit()->setClearButtonEnabled(true);
+ ui->cmbEncloseSelection->lineEdit()->setPlaceholderText(QStringLiteral("Feature is not active"));
+ ui->cmbEncloseSelection->addItem(QString(), KateViewConfig::None);
+ ui->cmbEncloseSelection->setItemData(0, i18n("Disable Feature"), Qt::ToolTipRole);
+ ui->cmbEncloseSelection->addItem(QStringLiteral("`*_~"), KateViewConfig::MarkDown);
+ ui->cmbEncloseSelection->setItemData(1, i18n("May handy with Markdown"), Qt::ToolTipRole);
+ ui->cmbEncloseSelection->addItem(QStringLiteral("<>(){}[]"), KateViewConfig::MirrorChar);
+ ui->cmbEncloseSelection->setItemData(2, i18n("Mirror characters, similar but not exact like auto brackets"), Qt::ToolTipRole);
+ ui->cmbEncloseSelection->addItem(QStringLiteral("´`_.:|#@~*!?$%/=,;-+^°§&"), KateViewConfig::NonLetters);
+ ui->cmbEncloseSelection->setItemData(3, i18n("Non letter character"), Qt::ToolTipRole);
+ const QStringList userLetters = KateViewConfig::global()->value(KateViewConfig::UserSetsOfCharsToEncloseSelection).toStringList();
+ for (int i = 0; i < userLetters.size(); ++i) {
+ ui->cmbEncloseSelection->addItem(userLetters.at(i), KateViewConfig::UserData + i);
+ }
+ ui->cmbEncloseSelection->setCurrentIndex(ui->cmbEncloseSelection->findText(KateViewConfig::global()->charsToEncloseSelection()));
+
const int id = static_cast(KateViewConfig::global()->inputMode());
ui->cmbInputMode->setCurrentIndex(ui->cmbInputMode->findData(id));
+
}
QString KateEditGeneralConfigTab::name() const
diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@ -3051,6 +3051,15 @@
}
}
+ // Treat some char also as "auto bracket" only when we have a selection
+ if (view->selection() && closingBracket.isNull() && view->config()->encloseSelectionInChars()) {
+ const QChar typedChar = chars.at(0);
+ if (view->config()->charsToEncloseSelection().contains(typedChar)) {
+ // Always the mirrored cause no harm, but allow funny brackets
+ closingBracket = typedChar.mirroredChar();
+ }
+ }
+
editStart();
/**
diff --git a/src/utils/kateconfig.h b/src/utils/kateconfig.h
--- a/src/utils/kateconfig.h
+++ b/src/utils/kateconfig.h
@@ -985,6 +985,7 @@
ShowWordCount,
TextDragAndDrop,
SmartCopyCut,
+ UserSetsOfCharsToEncloseSelection,
ViInputModeStealKeys,
ViRelativeLineNumbers,
WordCompletion,
@@ -1240,6 +1241,24 @@
return value(AutoBrackets).toBool();
}
+ enum SetOfCharsToEncloseSelection {
+ None,
+ MarkDown,
+ NonLetters,
+ MirrorChar,
+ UserData // Ensure to keep it at bottom of this list
+ };
+
+ bool encloseSelectionInChars() const
+ {
+ return !value(CharsToEncloseSelection).toString().isEmpty();
+ }
+
+ QString charsToEncloseSelection() const
+ {
+ return value(CharsToEncloseSelection).toString();
+ }
+
bool backspaceRemoveComposed() const
{
return value(BackspaceRemoveComposedCharacters).toBool();
diff --git a/src/utils/kateconfig.cpp b/src/utils/kateconfig.cpp
--- a/src/utils/kateconfig.cpp
+++ b/src/utils/kateconfig.cpp
@@ -523,7 +523,7 @@
addConfigEntry(ConfigEntry(AutomaticCompletionInvocation, "Auto Completion", QString(), true));
addConfigEntry(ConfigEntry(BackspaceRemoveComposedCharacters, "Backspace Remove Composed Characters", QString(), false));
addConfigEntry(ConfigEntry(BookmarkSorting, "Bookmark Menu Sorting", QString(), 0));
- addConfigEntry(ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QString(), QString()));
+ addConfigEntry(ConfigEntry(CharsToEncloseSelection, "Chars To Enclose Selection", QStringLiteral("enclose-selection"), QString()));
addConfigEntry(ConfigEntry(DefaultMarkType, "Default Mark Type", QStringLiteral("default-mark-type"), KTextEditor::MarkInterface::markType01, [](const QVariant &value) { return isPositive(value); }));
addConfigEntry(ConfigEntry(DynWordWrapAlignIndent, "Dynamic Word Wrap Align Indent", QString(), 80, [](const QVariant &value) { return inBounds(1, value, 100); }));
addConfigEntry(ConfigEntry(DynWordWrapIndicators, "Dynamic Word Wrap Indicators", QString(), 1, [](const QVariant &value) { return inBounds(1, value, 3); }));
@@ -552,6 +552,7 @@
addConfigEntry(ConfigEntry(ShowWordCount, "Show Word Count", QString(), false));
addConfigEntry(ConfigEntry(TextDragAndDrop, "Text Drag And Drop", QString(), true));
addConfigEntry(ConfigEntry(SmartCopyCut, "Smart Copy Cut", QString(), false));
+ addConfigEntry(ConfigEntry(UserSetsOfCharsToEncloseSelection, "User Sets Of Chars To Enclose Selection", QString(), QStringList()));
addConfigEntry(ConfigEntry(ViInputModeStealKeys, "Vi Input Mode Steal Keys", QString(), false));
addConfigEntry(ConfigEntry(ViRelativeLineNumbers, "Vi Relative Line Numbers", QString(), false));
addConfigEntry(ConfigEntry(WordCompletion, "Word Completion", QString(), true));
@@ -610,7 +611,6 @@
KTextEditor::EditorPrivate::config()->sync();
}
}
-
//END
//BEGIN KateRendererConfig