17#include "clipboardhistorydialog.h"
18#include "export/exporter.h"
19#include "inlinenotedata.h"
20#include "kateabstractinputmode.h"
21#include "kateautoindent.h"
22#include "katebookmarks.h"
23#include "katebuffer.h"
24#include "katecompletionwidget.h"
25#include "kateconfig.h"
26#include "katedialogs.h"
27#include "katedocument.h"
28#include "kateglobal.h"
29#include "katehighlight.h"
30#include "katehighlightmenu.h"
31#include "katekeywordcompletion.h"
32#include "katelayoutcache.h"
33#include "katemessagewidget.h"
34#include "katemodemenu.h"
35#include "katepartdebug.h"
36#include "katerenderer.h"
37#include "katestatusbar.h"
38#include "katetemplatehandler.h"
39#include "katetextline.h"
40#include "kateundomanager.h"
41#include "kateviewhelpers.h"
42#include "kateviewinternal.h"
43#include "katewordcompletion.h"
44#include "printing/kateprinter.h"
45#include "screenshotdialog.h"
46#include "script/katescriptaction.h"
47#include "script/katescriptmanager.h"
48#include "spellcheck/spellcheck.h"
49#include "spellcheck/spellcheckdialog.h"
50#include "spellcheck/spellingmenu.h"
52#include <KTextEditor/Message>
53#include <ktexteditor/annotationinterface.h>
54#include <ktexteditor/inlinenoteprovider.h>
55#include <ktexteditor/texthintinterface.h>
57#include <KActionCollection>
59#include <KConfigGroup>
62#include <KSelectAction>
63#include <KStandardActions>
64#include <KStandardShortcut>
65#include <KToggleAction>
66#include <KXMLGUIFactory>
68#include <QActionGroup>
69#include <QApplication>
74#include <QInputDialog>
79#include <QRegularExpression>
80#include <QTextToSpeech>
92 return doc->isComment(0, line.
firstChar());
108 , m_completionWidget(nullptr)
109 , m_annotationModel(nullptr)
110 , m_markedSelection(false)
113 , m_textFolding(doc->buffer())
114 , m_config(new KateViewConfig(this))
115 , m_renderer(new
KateRenderer(doc, m_textFolding, this))
116 , m_viewInternal(new KateViewInternal(this))
117 , m_spell(new KateSpellCheckDialog(this))
118 , m_bookmarks(new KateBookmarks(this))
124 , m_updatingDocumentConfig(false)
125 , m_selection(m_doc->buffer(),
KTextEditor::
Range::invalid(), Kate::TextRange::ExpandLeft, Kate::TextRange::AllowEmpty)
127 , m_bottomViewBar(nullptr)
129 , m_dictionaryBar(nullptr)
130 , m_spellingMenu(new KateSpellingMenu(this))
131 , m_userContextMenuSet(false)
132 , m_lineToUpdateRange(
KTextEditor::LineRange::invalid())
133 , m_mainWindow(mainWindow ? mainWindow :
KTextEditor::EditorPrivate::self()->dummyMainWindow())
134 , m_statusBar(nullptr)
135 , m_temporaryAutomaticInvocationDisabled(false)
136 , m_autoFoldedFirstLine(false)
139 connect(
this, &KTextEditor::ViewPrivate::delayedUpdateOfView,
this, &KTextEditor::ViewPrivate::slotDelayedUpdateOfView,
Qt::QueuedConnection);
141 m_delayedUpdateTimer.setSingleShot(
true);
142 m_delayedUpdateTimer.setInterval(0);
149 m_selection.setView(
this);
152 m_selection.setZDepth(-100000.0);
157 QWidget *bottomBarParent = m_mainWindow->createViewBar(
this);
159 m_bottomViewBar =
new KateViewBar(bottomBarParent !=
nullptr, bottomBarParent ? bottomBarParent : this, this);
167 m_bottomViewBar->installEventFilter(m_viewInternal);
180 if (bottomBarParent) {
181 m_mainWindow->addWidgetToViewBar(
this, m_bottomViewBar);
186 m_notificationLayout->setContentsMargins(20, 20, 20, 20);
187 m_viewInternal->setLayout(m_notificationLayout);
190 m_viewInternal->updateView();
194 setFocusProxy(m_viewInternal);
197 setXMLFile(QStringLiteral(
"katepart5ui.rc"));
203 new KateWordCompletionView(
this, actionCollection());
212 m_startingUp =
false;
218 for (
auto messageWidget : m_messageWidgets) {
236 connect(
this, &KTextEditor::ViewPrivate::displayRangeChanged,
this, &KTextEditor::ViewPrivate::createHighlights);
245KTextEditor::ViewPrivate::~ViewPrivate()
255 delete m_completionWidget;
263 delete m_viewInternal;
266 m_mainWindow->deleteViewBar(
this);
267 m_bottomViewBar =
nullptr;
274void KTextEditor::ViewPrivate::toggleStatusBar()
278 bottomViewBar()->removePermanentBarWidget(m_statusBar);
280 m_statusBar =
nullptr;
281 Q_EMIT statusBarEnabledChanged(
this,
false);
286 m_statusBar =
new KateStatusBar(
this);
287 bottomViewBar()->addPermanentBarWidget(m_statusBar);
288 Q_EMIT statusBarEnabledChanged(
this,
true);
291void KTextEditor::ViewPrivate::setupLayout()
322 if (frameAroundContents) {
327 layout->
addItem(m_topSpacer, 1, 0, 1, 4);
330 layout->
addItem(m_leftSpacer, 2, 0, 1, 1);
333 layout->
addWidget(m_viewInternal->m_leftBorder, 2, 1, 1, 1);
336 layout->
addWidget(m_viewInternal, 2, 2, 1, 1);
339 layout->
addItem(m_rightSpacer, 2, 3, 1, 1);
342 layout->
addItem(m_bottomSpacer, 3, 0, 1, 4);
345 layout->
addWidget(m_viewInternal->m_lineScroll, 1, 4, 3, 1);
348 layout->
addWidget(m_viewInternal->m_columnScroll, 4, 0, 1, 4);
351 layout->
addWidget(m_viewInternal->m_dummy, 4, 4, 1, 1);
357 if (m_bottomViewBar->parentWidget() ==
this) {
358 layout->
addWidget(m_bottomViewBar, 6, 0, 1, 5);
367 m_viewInternal->m_lineScroll->setAutoFillBackground(
false);
370 m_viewInternal->m_columnScroll->setAutoFillBackground(
false);
377 layout->
addItem(m_topSpacer, 1, 0, 1, 5);
380 layout->
addItem(m_leftSpacer, 2, 0, 1, 1);
383 layout->
addWidget(m_viewInternal->m_leftBorder, 2, 1, 1, 1);
386 layout->
addWidget(m_viewInternal, 2, 2, 1, 1);
389 layout->
addWidget(m_viewInternal->m_lineScroll, 2, 3, 1, 1);
392 layout->
addItem(m_rightSpacer, 2, 4, 1, 1);
395 layout->
addWidget(m_viewInternal->m_columnScroll, 3, 1, 1, 2);
398 layout->
addWidget(m_viewInternal->m_dummy, 3, 3, 1, 1);
401 layout->
addItem(m_bottomSpacer, 4, 0, 1, 5);
407 if (m_bottomViewBar->parentWidget() ==
this) {
408 layout->
addWidget(m_bottomViewBar, 6, 0, 1, 5);
417 m_viewInternal->m_lineScroll->setAutoFillBackground(
true);
419 m_viewInternal->m_columnScroll->setBackgroundRole(
QPalette::Base);
420 m_viewInternal->m_columnScroll->setAutoFillBackground(
true);
424void KTextEditor::ViewPrivate::setupConnections()
426 connect(m_doc, &KTextEditor::DocumentPrivate::undoChanged,
this, &KTextEditor::ViewPrivate::slotUpdateUndo);
429 connect(m_viewInternal, &KateViewInternal::dropEventPass,
this, &KTextEditor::ViewPrivate::dropEventPass);
431 connect(m_doc, &KTextEditor::DocumentPrivate::annotationModelChanged, m_viewInternal->m_leftBorder, &KateIconBorder::annotationModelChanged);
434void KTextEditor::ViewPrivate::goToPreviousEditingPosition()
436 auto c = doc()->
lastEditingPosition(KTextEditor::DocumentPrivate::Previous, cursorPosition());
438 setCursorPosition(c);
442void KTextEditor::ViewPrivate::goToNextEditingPosition()
446 setCursorPosition(c);
449void KTextEditor::ViewPrivate::setupActions()
454 m_toggleWriteLock =
nullptr;
457 a->
setWhatsThis(
i18n(
"Cut the selected text and move it to the clipboard"));
465 a->
setWhatsThis(
i18n(
"Use this command to copy the currently selected text to the system clipboard."));
467 m_clipboardHistory = a = ac->
addAction(QStringLiteral(
"clipboard_history_paste"),
this, [
this] {
468 ClipboardHistoryDialog chd(mainWindow()->
window(),
this);
475 m_pasteSelection = a = ac->
addAction(QStringLiteral(
"edit_paste_selection"),
this, &KTextEditor::ViewPrivate::pasteSelection);
481 a = ac->
addAction(QStringLiteral(
"edit_copy_file_location"),
this, &KTextEditor::ViewPrivate::copyFileLocation);
486 m_swapWithClipboard = a = ac->
addAction(QStringLiteral(
"edit_swap_with_clipboard"),
this, &KTextEditor::ViewPrivate::swapWithClipboard);
488 a->
setWhatsThis(
i18n(
"Swap the selected text with the clipboard contents"));
490 m_screenshotSelection = a = ac->
addAction(QStringLiteral(
"text_screenshot_selection"),
this, &KTextEditor::ViewPrivate::screenshot);
493 if (!doc()->readOnly()) {
506 ac->
addAction(QStringLiteral(
"tools_scripts"), m_scriptActionMenu.get());
508 a = ac->
addAction(QStringLiteral(
"tools_apply_wordwrap"));
511 i18n(
"Use this to wrap the current line, or to reformat the selected lines as paragraph, "
512 "to fit the 'Wrap words at' setting in the configuration dialog.<br /><br />"
513 "This is a static word wrap, meaning the document is changed."));
516 a = ac->
addAction(QStringLiteral(
"tools_cleanIndent"));
519 i18n(
"Use this to clean the indentation of a selected block of text (only tabs/only spaces).<br /><br />"
520 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
523 a = ac->
addAction(QStringLiteral(
"tools_formatIndent"));
525 a->
setWhatsThis(
i18n(
"Use this to auto indent the current line or block of text to its proper indent level."));
528 a = ac->
addAction(QStringLiteral(
"tools_alignOn"));
531 i18n(
"This command aligns lines in the selected block or whole document on the column given by a regular expression "
532 "that you will be prompted for.<br /><br />"
533 "If you give an empty pattern it will align on the first non-blank character by default.<br />"
534 "If the pattern has a capture it will indent on the captured match.<br /><br />"
535 "<i>Examples</i>:<br />"
536 "With '-' it will insert spaces before the first '-' of each lines to align them all on the same column.<br />"
537 "With ':\\s+(.)' it will insert spaces before the first non-blank character that occurs after a colon to align "
538 "them all on the same column."));
541 a = ac->
addAction(QStringLiteral(
"tools_comment"));
545 i18n(
"This command comments out the current line or a selected block of text.<br /><br />"
546 "The characters for single/multiple line comments are defined within the language's highlighting."));
549 a = ac->
addAction(QStringLiteral(
"Previous Editing Line"));
550 a->
setText(
i18n(
"Go to Previous Editing Location"));
555 a = ac->
addAction(QStringLiteral(
"Next Editing Line"));
561 a = ac->
addAction(QStringLiteral(
"tools_uncomment"));
565 i18n(
"This command removes comments from the current line or a selected block of text.<br /><br />"
566 "The characters for single/multiple line comments are defined within the language's highlighting."));
569 a = ac->
addAction(QStringLiteral(
"tools_toggle_comment"));
578 ac->
addAction(QStringLiteral(
"tools_toggle_write_lock"), a);
583 m_forceRTL = checked;
587 ac->
addAction(QStringLiteral(
"force_rtl_direction"), a);
589 a = ac->
addAction(QStringLiteral(
"tools_uppercase"));
594 i18n(
"Convert the selection to uppercase, or the character to the "
595 "right of the cursor if no text is selected."));
598 a = ac->
addAction(QStringLiteral(
"tools_lowercase"));
603 i18n(
"Convert the selection to lowercase, or the character to the "
604 "right of the cursor if no text is selected."));
607 a = ac->
addAction(QStringLiteral(
"tools_capitalize"));
612 i18n(
"Capitalize the selection, or the word under the "
613 "cursor if no text is selected."));
616 a = ac->
addAction(QStringLiteral(
"tools_join_lines"));
621 a = ac->
addAction(QStringLiteral(
"tools_invoke_code_completion"));
623 a->
setWhatsThis(
i18n(
"Manually invoke command completion, usually by using a shortcut bound to this action."));
627 a = ac->
addAction(QStringLiteral(
"remove_trailing_spaces"));
633 for (
auto *action : {m_cut, m_paste, m_clipboardHistory, m_swapWithClipboard}) {
634 action->setEnabled(
false);
637 if (m_pasteSelection) {
638 m_pasteSelection->setEnabled(
false);
641 m_editUndo =
nullptr;
642 m_editRedo =
nullptr;
651 a = ac->
addAction(QStringLiteral(
"file_reload"));
659 a->
setWhatsThis(
i18n(
"Save the current document to disk, with a name of your choice."));
661 a =
new KateViewEncodingAction(m_doc,
this,
i18nc(
"@action",
"Save As with Encoding…"),
this,
true );
663 ac->
addAction(QStringLiteral(
"file_save_as_with_encoding"), a);
665 a = ac->
addAction(QStringLiteral(
"file_save_copy_as"));
672 a->
setWhatsThis(
i18n(
"This command opens a dialog and lets you choose a line that you want the cursor to move to."));
674 a = ac->
addAction(QStringLiteral(
"modified_line_up"));
680 a = ac->
addAction(QStringLiteral(
"modified_line_down"));
686 a = ac->
addAction(QStringLiteral(
"set_confdlg"));
692 m_modeAction =
new KateModeMenu(
i18n(
"&Mode"),
this);
693 ac->
addAction(QStringLiteral(
"tools_mode"), m_modeAction);
695 "Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
696 m_modeAction->updateMenu(m_doc);
698 KateHighlightingMenu *menu =
new KateHighlightingMenu(
i18n(
"&Highlighting"),
this);
699 ac->
addAction(QStringLiteral(
"tools_highlighting"), menu);
700 menu->
setWhatsThis(
i18n(
"Here you can choose how the current document should be highlighted."));
701 menu->updateMenu(m_doc);
703 KateViewSchemaAction *schemaMenu =
new KateViewSchemaAction(
i18n(
"&Editor Color Theme"),
this);
705 ac->
addAction(QStringLiteral(
"view_schemas"), schemaMenu);
706 schemaMenu->updateMenu(
this);
710 ac->
addAction(QStringLiteral(
"tools_indentation"), indentMenu);
719 a->
setWhatsThis(
i18n(
"If you have selected something within the current document, this will no longer be selected."));
721 a = ac->
addAction(QStringLiteral(
"view_inc_font_sizes"));
727 m_viewInternal->slotIncFontSizes();
730 a = ac->
addAction(QStringLiteral(
"view_dec_font_sizes"));
732 a->setText(
i18n(
"Shrink Font"));
734 a->setWhatsThis(
i18n(
"This decreases the display font size."));
736 m_viewInternal->slotDecFontSizes();
739 a = ac->
addAction(QStringLiteral(
"view_reset_font_sizes"));
741 a->setText(
i18n(
"Reset Font Size"));
743 a->setWhatsThis(
i18n(
"This resets the display font size."));
746 a = m_toggleBlockSelection =
new KToggleAction(
i18n(
"Bl&ock Selection Mode"),
this);
747 ac->
addAction(QStringLiteral(
"set_verticalSelect"), a);
749 a->setWhatsThis(
i18n(
"This command allows switching between the normal (line based) selection mode and the block selection mode."));
752 a = ac->
addAction(QStringLiteral(
"switch_next_input_mode"));
755 a->setWhatsThis(
i18n(
"Switch to the next input mode."));
759 ac->
addAction(QStringLiteral(
"set_insert"), a);
761 a->setWhatsThis(
i18n(
"Choose whether you want the text you type to be inserted or to overwrite existing text."));
765 a = m_toggleShowSpace = toggleAction =
new KToggleAction(
i18n(
"Show Whitespace"),
this);
766 ac->
addAction(QStringLiteral(
"view_show_whitespaces"), a);
768 i18n(
"If this option is checked, whitespaces in this document will be visible.<br /><br />"
769 "This is only a view option, meaning the document will not be changed."));
772 a = m_toggleDynWrap = toggleAction =
new KToggleAction(
i18n(
"&Dynamic Word Wrap"),
this);
774 ac->
addAction(QStringLiteral(
"view_dynamic_word_wrap"), a);
776 i18n(
"If this option is checked, the text lines will be wrapped at the view border on the screen.<br /><br />"
777 "This is only a view option, meaning the document will not be changed."));
780 a = m_setDynWrapIndicators =
new KSelectAction(
i18n(
"Dynamic Word Wrap Indicators"),
this);
781 ac->
addAction(QStringLiteral(
"dynamic_word_wrap_indicators"), a);
782 a->
setWhatsThis(
i18n(
"Choose when the Dynamic Word Wrap Indicators should be displayed"));
785 m_setDynWrapIndicators->setItems(list2);
786 m_setDynWrapIndicators->setEnabled(m_toggleDynWrap->isChecked());
789 ac->
addAction(QStringLiteral(
"view_static_word_wrap"), a);
790 a->
setWhatsThis(
i18n(
"If this option is checked, the text lines will be wrapped at the column defined in the editing properties."));
793 m_doc->setWordWrap(!m_doc->wordWrap());
797 a = toggleAction = m_toggleWWMarker =
new KToggleAction(
i18n(
"Show Static &Word Wrap Marker"),
this);
798 ac->
addAction(QStringLiteral(
"view_word_wrap_marker"), a);
800 i18n(
"Show/hide the Word Wrap Marker, a vertical line drawn at the word "
801 "wrap column as defined in the editing properties"));
804 a = toggleAction = m_toggleFoldingMarkers =
new KToggleAction(
i18n(
"Show Folding &Markers"),
this);
805 ac->
addAction(QStringLiteral(
"view_folding_markers"), a);
806 a->
setWhatsThis(
i18n(
"You can choose if the codefolding marks should be shown, if codefolding is possible."));
809 a = m_toggleIconBar = toggleAction =
new KToggleAction(
i18n(
"Show &Icon Border"),
this);
810 ac->
addAction(QStringLiteral(
"view_border"), a);
811 a->
setWhatsThis(
i18n(
"Show/hide the icon border.<br /><br />The icon border shows bookmark symbols, for instance."));
814 a = toggleAction = m_toggleLineNumbers =
new KToggleAction(
i18n(
"Show &Line Numbers"),
this);
815 ac->
addAction(QStringLiteral(
"view_line_numbers"), a);
816 a->
setWhatsThis(
i18n(
"Show/hide the line numbers on the left hand side of the view."));
819 a = m_toggleScrollBarMarks = toggleAction =
new KToggleAction(
i18n(
"Show Scroll&bar Marks"),
this);
820 ac->
addAction(QStringLiteral(
"view_scrollbar_marks"), a);
821 a->
setWhatsThis(
i18n(
"Show/hide the marks on the vertical scrollbar.<br /><br />The marks show bookmarks, for instance."));
824 a = m_toggleScrollBarMiniMap = toggleAction =
new KToggleAction(
i18n(
"Show Scrollbar Mini-Map"),
this);
825 ac->
addAction(QStringLiteral(
"view_scrollbar_minimap"), a);
826 a->
setWhatsThis(
i18n(
"Show/hide the mini-map on the vertical scrollbar.<br /><br />The mini-map shows an overview of the whole document."));
829 a = m_doc->autoReloadToggleAction();
830 ac->
addAction(QStringLiteral(
"view_auto_reload"), a);
838 a = m_toggleNPSpaces =
new KToggleAction(
i18n(
"Show Non-Printable Spaces"),
this);
839 ac->
addAction(QStringLiteral(
"view_non_printable_spaces"), a);
840 a->
setWhatsThis(
i18n(
"Show/hide bounding box around non-printable spaces"));
843 a = m_switchCmdLine = ac->
addAction(QStringLiteral(
"switch_to_cmd_line"));
846 a->setWhatsThis(
i18n(
"Show/hide the command line on the bottom of the view."));
851 ac->
addAction(QStringLiteral(
"view_input_modes"), am);
852 auto switchInputModeAction = ac->
action(QStringLiteral(
"switch_next_input_mode"));
855 for (
const auto &mode : m_viewInternal->m_inputModes) {
856 a =
new QAction(mode->viewInputModeHuman(), m_inputModeActions);
858 a->setWhatsThis(
i18n(
"Activate/deactivate %1", mode->viewInputModeHuman()));
859 const InputMode im = mode->viewInputMode();
860 a->setData(
static_cast<int>(im));
861 a->setCheckable(
true);
862 if (im == m_config->inputMode()) {
869 ac->
addAction(QStringLiteral(
"set_eol"), a);
870 a->
setWhatsThis(
i18n(
"Choose which line endings should be used, when you save the document"));
872 i18nc(
"@item:inmenu End of Line",
"&Windows/DOS"),
873 i18nc(
"@item:inmenu End of Line",
"&Macintosh")};
874 m_setEndOfLine->setItems(list);
875 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
879 m_addBom->setChecked(doc()->config()->
bom());
880 ac->
addAction(QStringLiteral(
"add_bom"), a);
881 a->
setWhatsThis(
i18n(
"Enable/disable adding of byte order marks for UTF-8/UTF-16 encoded files while saving"));
885 m_encodingAction =
new KateViewEncodingAction(m_doc,
this,
i18n(
"E&ncoding"),
this);
886 ac->
addAction(QStringLiteral(
"set_encoding"), m_encodingAction);
889 a->
setWhatsThis(
i18n(
"Look up the first occurrence of a piece of text or regular expression."));
892 a = ac->
addAction(QStringLiteral(
"edit_find_selected"));
895 a->setWhatsThis(
i18n(
"Finds next occurrence of selected text."));
898 a = ac->
addAction(QStringLiteral(
"edit_find_selected_backwards"));
901 a->setWhatsThis(
i18n(
"Finds previous occurrence of selected text."));
904 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_next_occurrence"));
905 a->
setText(
i18n(
"Find and Select Next Occurrence"));
907 a->setWhatsThis(
i18n(
"Finds next occurrence of the word under cursor and add it to selection."));
910 a = ac->
addAction(QStringLiteral(
"edit_skip_multicursor_current_occurrence"));
911 a->
setText(
i18n(
"Mark Currently Selected Occurrence as Skipped"));
913 a->setWhatsThis(
i18n(
"Marks the currently selected word as skipped."));
916 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_all_occurrences"));
917 a->
setText(
i18n(
"Find and Select All Occurrences"));
919 a->setWhatsThis(
i18n(
"Finds all occurrences of the word under cursor and selects them."));
927 a->
setWhatsThis(
i18n(
"Look up the previous occurrence of the search phrase."));
931 a->
setWhatsThis(
i18n(
"Look up a piece of text or regular expression and replace the result with some given text."));
933 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_from_sel"));
936 a->setWhatsThis(
i18n(
"Creates a cursor at the end of every line in selection."));
939 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_down"));
942 a->setWhatsThis(
i18n(
"Adds a caret in the line below the current caret."));
945 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_up"));
948 a->setWhatsThis(
i18n(
"Adds a caret in the line above the current caret."));
951 a = ac->
addAction(QStringLiteral(
"edit_toggle_camel_case_cursor"));
952 a->
setText(
i18n(
"Toggle Camel Case Cursor Movement"));
953 a->setWhatsThis(
i18n(
"Toggle between normal word movement and camel case cursor movement."));
956 a = ac->
addAction(QStringLiteral(
"edit_remove_cursors_from_empty_lines"));
957 a->
setText(
i18n(
"Remove Cursors from Empty Lines"));
958 a->setWhatsThis(
i18n(
"Remove cursors from empty lines"));
961 m_spell->createActions(ac);
962 m_toggleOnTheFlySpellCheck =
new KToggleAction(
i18n(
"Automatic Spell Checking"),
this);
963 m_toggleOnTheFlySpellCheck->setWhatsThis(
i18n(
"Enable/disable automatic spell checking"));
965 ac->
addAction(QStringLiteral(
"tools_toggle_automatic_spell_checking"), m_toggleOnTheFlySpellCheck);
968 a = ac->
addAction(QStringLiteral(
"tools_change_dictionary"));
970 a->setWhatsThis(
i18n(
"Change the dictionary that is used for spell checking."));
973 a = ac->
addAction(QStringLiteral(
"tools_clear_dictionary_ranges"));
975 a->setEnabled(
false);
976 a->setWhatsThis(
i18n(
"Remove all the separate dictionary ranges that were set for spell checking."));
980 m_copyHtmlAction = ac->
addAction(QStringLiteral(
"edit_copy_html"),
this, SLOT(exportHtmlToClipboard()));
982 m_copyHtmlAction->setText(
i18n(
"Copy as &HTML"));
983 m_copyHtmlAction->setWhatsThis(
i18n(
"Use this command to copy the currently selected text as HTML to the system clipboard."));
985 a = ac->
addAction(QStringLiteral(
"file_export_html"),
this, SLOT(exportHtmlToFile()));
987 a->setText(
i18nc(
"@action",
"E&xport as HTML…"));
989 i18n(
"This command allows you to export the current document"
990 " with all highlighting information into a HTML document."));
992 m_spellingMenu->createActions(ac);
994 m_bookmarks->createActions(ac);
996 slotSelectionChanged();
1002 setupSpeechActions();
1006 const auto actions = ac->
actions();
1007 for (
QAction *action : actions) {
1014void KTextEditor::ViewPrivate::slotConfigDialog()
1020void KTextEditor::ViewPrivate::setupEditActions()
1031 m_editActions.push_back(a);
1033 a = ac->
addAction(QStringLiteral(
"select_char_left"));
1037 m_editActions.push_back(a);
1039 a = ac->
addAction(QStringLiteral(
"select_word_left"));
1043 m_editActions.push_back(a);
1045 a = ac->
addAction(QStringLiteral(
"word_right"));
1049 m_editActions.push_back(a);
1051 a = ac->
addAction(QStringLiteral(
"select_char_right"));
1055 m_editActions.push_back(a);
1057 a = ac->
addAction(QStringLiteral(
"select_word_right"));
1061 m_editActions.push_back(a);
1063 a = ac->
addAction(QStringLiteral(
"mark_selection"));
1065 a->
setWhatsThis(
i18n(
"Emulate the Emacs-like selection mode, where the beginning is marked and then the selection is continuously updated."));
1067 m_editActions.push_back(a);
1069 a = ac->
addAction(QStringLiteral(
"beginning_of_line"));
1073 m_editActions.push_back(a);
1075 a = ac->
addAction(QStringLiteral(
"beginning_of_document"));
1076 a->
setText(
i18n(
"Move to Beginning of Document"));
1079 m_editActions.push_back(a);
1081 a = ac->
addAction(QStringLiteral(
"select_beginning_of_line"));
1085 m_editActions.push_back(a);
1087 a = ac->
addAction(QStringLiteral(
"select_beginning_of_document"));
1088 a->
setText(
i18n(
"Select to Beginning of Document"));
1091 m_editActions.push_back(a);
1093 a = ac->
addAction(QStringLiteral(
"end_of_line"));
1097 m_editActions.push_back(a);
1099 a = ac->
addAction(QStringLiteral(
"end_of_document"));
1103 m_editActions.push_back(a);
1105 a = ac->
addAction(QStringLiteral(
"select_end_of_line"));
1109 m_editActions.push_back(a);
1111 a = ac->
addAction(QStringLiteral(
"select_end_of_document"));
1115 m_editActions.push_back(a);
1117 a = ac->
addAction(QStringLiteral(
"select_line_up"));
1121 m_editActions.push_back(a);
1123 a = ac->
addAction(QStringLiteral(
"scroll_line_up"));
1127 m_editActions.push_back(a);
1129 a = ac->
addAction(QStringLiteral(
"move_line_down"));
1133 m_editActions.push_back(a);
1135 a = ac->
addAction(QStringLiteral(
"move_line_up"));
1139 m_editActions.push_back(a);
1141 a = ac->
addAction(QStringLiteral(
"move_cursor_right"));
1145 m_editActions.push_back(a);
1147 a = ac->
addAction(QStringLiteral(
"move_cursor_left"));
1151 m_editActions.push_back(a);
1153 a = ac->
addAction(QStringLiteral(
"select_line_down"));
1157 m_editActions.push_back(a);
1159 a = ac->
addAction(QStringLiteral(
"scroll_line_down"));
1163 m_editActions.push_back(a);
1165 a = ac->
addAction(QStringLiteral(
"scroll_page_up"));
1169 m_editActions.push_back(a);
1171 a = ac->
addAction(QStringLiteral(
"select_page_up"));
1175 m_editActions.push_back(a);
1177 a = ac->
addAction(QStringLiteral(
"move_top_of_view"));
1181 m_editActions.push_back(a);
1183 a = ac->
addAction(QStringLiteral(
"select_top_of_view"));
1187 m_editActions.push_back(a);
1189 a = ac->
addAction(QStringLiteral(
"scroll_page_down"));
1193 m_editActions.push_back(a);
1195 a = ac->
addAction(QStringLiteral(
"select_page_down"));
1199 m_editActions.push_back(a);
1201 a = ac->
addAction(QStringLiteral(
"move_bottom_of_view"));
1205 m_editActions.push_back(a);
1207 a = ac->
addAction(QStringLiteral(
"select_bottom_of_view"));
1211 m_editActions.push_back(a);
1213 a = ac->
addAction(QStringLiteral(
"to_matching_bracket"));
1219 a = ac->
addAction(QStringLiteral(
"select_matching_bracket"));
1226 if (!doc()->readOnly()) {
1227 a = ac->
addAction(QStringLiteral(
"transpose_char"));
1230 m_editActions.push_back(a);
1232 a = ac->
addAction(QStringLiteral(
"transpose_word"));
1235 m_editActions.push_back(a);
1237 a = ac->
addAction(QStringLiteral(
"delete_line"));
1241 m_editActions.push_back(a);
1243 a = ac->
addAction(QStringLiteral(
"delete_word_left"));
1247 m_editActions.push_back(a);
1249 a = ac->
addAction(QStringLiteral(
"delete_word_right"));
1253 m_editActions.push_back(a);
1255 a = ac->
addAction(QStringLiteral(
"delete_next_character"));
1259 m_editActions.push_back(a);
1261 a = ac->
addAction(QStringLiteral(
"backspace"));
1267 m_editActions.push_back(a);
1269 a = ac->
addAction(QStringLiteral(
"insert_tabulator"));
1272 m_editActions.push_back(a);
1274 a = ac->
addAction(QStringLiteral(
"smart_newline"));
1276 a->
setWhatsThis(
i18n(
"Insert newline including leading characters of the current line which are not letters or numbers."));
1281 m_editActions.push_back(a);
1283 a = ac->
addAction(QStringLiteral(
"no_indent_newline"));
1284 a->
setText(
i18n(
"Insert a Non-Indented Newline"));
1285 a->
setWhatsThis(
i18n(
"Insert a new line without indentation, regardless of indentation settings."));
1290 m_editActions.push_back(a);
1292 a = ac->
addAction(QStringLiteral(
"newline_above"));
1293 a->
setText(
i18n(
"Insert a Newline Above Current Line"));
1294 a->
setWhatsThis(
i18n(
"Insert a new line above current line without modifying the current line."));
1299 m_editActions.push_back(a);
1301 a = ac->
addAction(QStringLiteral(
"newline_below"));
1302 a->
setText(
i18n(
"Insert a Newline Below Current Line"));
1303 a->
setWhatsThis(
i18n(
"Insert a new line below current line without modifying the current line."));
1308 m_editActions.push_back(a);
1310 a = ac->
addAction(QStringLiteral(
"tools_indent"));
1314 i18n(
"Use this to indent a selected block of text.<br /><br />"
1315 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
1319 a = ac->
addAction(QStringLiteral(
"tools_unindent"));
1334void KTextEditor::ViewPrivate::setupCodeFolding()
1339 a = ac->
addAction(QStringLiteral(
"folding_toplevel"));
1343 a = ac->
addAction(QStringLiteral(
"folding_expandtoplevel"));
1347 a = ac->
addAction(QStringLiteral(
"folding_toggle_current"));
1351 a = ac->
addAction(QStringLiteral(
"folding_toggle_in_current"));
1356void KTextEditor::ViewPrivate::setupSpeechActions()
1361 a->
setText(
i18n(
"Say current selection or document"));
1370 a = ac->
addAction(QStringLiteral(
"tools_speech_stop"));
1376 a = ac->
addAction(QStringLiteral(
"tools_speech_pause"));
1382 a = ac->
addAction(QStringLiteral(
"tools_speech_resume"));
1389void KTextEditor::ViewPrivate::slotFoldToplevelNodes()
1391 for (
int line = 0; line < doc()->
lines(); ++line) {
1392 if (textFolding().isLineVisible(line)) {
1398void KTextEditor::ViewPrivate::slotExpandToplevelNodes()
1400 const auto topLevelRanges(textFolding().foldingRangesForParentRange());
1401 for (
const auto &range : topLevelRanges) {
1402 textFolding().unfoldRange(range.first);
1406void KTextEditor::ViewPrivate::slotToggleFolding()
1408 int line = cursorPosition().line();
1409 bool actionDone =
false;
1410 while (!actionDone && (line > -1)) {
1411 actionDone = unfoldLine(line);
1413 actionDone = foldLine(line--).isValid();
1418void KTextEditor::ViewPrivate::slotToggleFoldingsInRange()
1420 int line = cursorPosition().line();
1421 while (!toggleFoldingsInRange(line) && (line > -1)) {
1429 if (!foldingRange.
isValid()) {
1430 return foldingRange;
1435 if (!m_doc->buffer().isFoldingStartingOnLine(line).second && !foldingRange.
onSingleLine()) {
1436 const int adjustedLine = foldingRange.
end().
line() - 1;
1444 auto folds = textFolding().foldingRangesStartingOnLine(line);
1445 for (
int i = 0; i < folds.size(); ++i) {
1447 if (fold == foldingRange) {
1448 return foldingRange;
1458 return foldingRange;
1461bool KTextEditor::ViewPrivate::unfoldLine(
int line)
1463 bool actionDone =
false;
1468 auto startingRanges = textFolding().foldingRangesStartingOnLine(line);
1469 for (
int i = 0; i < startingRanges.size() && !actionDone; ++i) {
1471 setCursorPosition(textFolding().foldingRange(startingRanges[i].first).
start());
1473 actionDone |= textFolding().unfoldRange(startingRanges[i].first);
1478 setCursorPosition(currentCursor);
1484bool KTextEditor::ViewPrivate::toggleFoldingOfLine(
int line)
1486 bool actionDone = unfoldLine(line);
1488 actionDone = foldLine(line).isValid();
1494bool KTextEditor::ViewPrivate::toggleFoldingsInRange(
int line)
1497 if (!foldingRange.
isValid()) {
1502 bool actionDone =
false;
1507 actionDone |= unfoldLine(line);
1511 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1512 actionDone |= unfoldLine(ln);
1517 setCursorPosition(currentCursor);
1523 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1527 ln = qMax(ln, fr.
end().
line() - 1);
1536 actionDone |= foldLine(line).isValid();
1545 return currentInputMode()->viewMode();
1548QString KTextEditor::ViewPrivate::viewModeHuman()
const
1550 QString currentMode = currentInputMode()->viewModeHuman();
1553 if (!doc()->isReadWrite()) {
1554 currentMode =
i18n(
"(R/O) %1", currentMode);
1563 return currentInputMode()->viewInputMode();
1566QString KTextEditor::ViewPrivate::viewInputModeHuman()
const
1568 return currentInputMode()->viewInputModeHuman();
1573 if (currentInputMode()->viewInputMode() == mode) {
1579 clearSecondaryCursors();
1582 m_viewInternal->m_currentInputMode->deactivate();
1583 m_viewInternal->m_currentInputMode = m_viewInternal->m_inputModes[mode].get();
1584 m_viewInternal->m_currentInputMode->activate();
1587 if (rememberInConfig) {
1588 config()->setValue(KateViewConfig::InputMode, mode);
1592 const auto inputModeActions = m_inputModeActions->actions();
1593 for (
QAction *action : inputModeActions) {
1594 if (
static_cast<InputMode
>(action->data().toInt()) == mode) {
1595 action->setChecked(
true);
1601 Q_EMIT viewInputModeChanged(
this, mode);
1602 Q_EMIT viewModeChanged(
this, viewMode());
1605void KTextEditor::ViewPrivate::slotDocumentAboutToReload()
1607 if (doc()->isAutoReload()) {
1608 const int lastVisibleLine = m_viewInternal->endLine();
1609 const int currentLine = cursorPosition().line();
1610 m_gotoBottomAfterReload = (lastVisibleLine == currentLine) && (currentLine == doc()->
lastLine());
1611 if (!m_gotoBottomAfterReload) {
1613 const int firstVisibleLine = 1 + lastVisibleLine - m_viewInternal->linesDisplayed();
1614 const int newLine = qBound(firstVisibleLine, currentLine, lastVisibleLine);
1618 m_gotoBottomAfterReload =
false;
1622void KTextEditor::ViewPrivate::slotDocumentReloaded()
1624 if (m_gotoBottomAfterReload) {
1629void KTextEditor::ViewPrivate::slotGotFocus()
1632 currentInputMode()->gotFocus();
1638 if (m_viewInternal->m_lineScroll->isVisible()) {
1639 m_viewInternal->m_lineScroll->update();
1642 if (m_viewInternal->m_columnScroll->isVisible()) {
1643 m_viewInternal->m_columnScroll->update();
1649void KTextEditor::ViewPrivate::slotLostFocus()
1652 currentInputMode()->lostFocus();
1658 if (m_viewInternal->m_lineScroll->isVisible()) {
1659 m_viewInternal->m_lineScroll->update();
1662 if (m_viewInternal->m_columnScroll->isVisible()) {
1663 m_viewInternal->m_columnScroll->update();
1666 if (doc()->config()->autoSave() && doc()->config()->autoSaveOnFocusOut() && doc()->isModified() && doc()->url().isLocalFile()) {
1667 doc()->documentSave();
1673void KTextEditor::ViewPrivate::setDynWrapIndicators(
int mode)
1675 config()->setValue(KateViewConfig::DynWordWrapIndicators, mode);
1678bool KTextEditor::ViewPrivate::isOverwriteMode()
const
1680 return doc()->
config()->ovr();
1683void KTextEditor::ViewPrivate::reloadFile()
1689void KTextEditor::ViewPrivate::slotReadWriteChanged()
1691 if (m_toggleWriteLock) {
1692 m_toggleWriteLock->setChecked(!doc()->isReadWrite());
1695 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
1696 m_paste->setEnabled(doc()->isReadWrite());
1697 if (m_pasteSelection) {
1698 m_pasteSelection->setEnabled(doc()->isReadWrite());
1700 m_swapWithClipboard->setEnabled(doc()->isReadWrite());
1701 m_setEndOfLine->setEnabled(doc()->isReadWrite());
1703 static const auto l = {QStringLiteral(
"edit_replace"),
1704 QStringLiteral(
"tools_spelling"),
1705 QStringLiteral(
"tools_indent"),
1706 QStringLiteral(
"tools_unindent"),
1707 QStringLiteral(
"tools_cleanIndent"),
1708 QStringLiteral(
"tools_formatIndet"),
1709 QStringLiteral(
"tools_alignOn"),
1710 QStringLiteral(
"tools_comment"),
1711 QStringLiteral(
"tools_uncomment"),
1712 QStringLiteral(
"tools_toggle_comment"),
1713 QStringLiteral(
"tools_uppercase"),
1714 QStringLiteral(
"tools_lowercase"),
1715 QStringLiteral(
"tools_capitalize"),
1716 QStringLiteral(
"tools_join_lines"),
1717 QStringLiteral(
"tools_apply_wordwrap"),
1718 QStringLiteral(
"tools_spelling_from_cursor"),
1719 QStringLiteral(
"tools_spelling_selection")};
1721 for (
const auto &action : l) {
1722 QAction *a = actionCollection()->action(action);
1729 currentInputMode()->readWriteChanged(doc()->isReadWrite());
1732 Q_EMIT viewModeChanged(
this, viewMode());
1733 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1736void KTextEditor::ViewPrivate::toggleCamelCaseCursor()
1738 const auto enabled = doc()->
config()->camelCursor();
1739 doc()->
config()->setCamelCursor(!enabled);
1752void KTextEditor::ViewPrivate::slotUpdateUndo()
1754 if (doc()->readOnly()) {
1758 m_editUndo->setEnabled(doc()->isReadWrite() && doc()->undoCount() > 0);
1759 m_editRedo->setEnabled(doc()->isReadWrite() && doc()->redoCount() > 0);
1762bool KTextEditor::ViewPrivate::setCursorPositionInternal(
const KTextEditor::Cursor position, uint tabwidth,
bool calledExternally)
1764 if (position.
line() < 0 || position.
line() >= doc()->lines()) {
1773 for (; z < line_str.
length() && z < position.
column(); z++) {
1775 x += tabwidth - (x % tabwidth);
1781 if (blockSelection()) {
1782 if (z < position.
column()) {
1783 x += position.
column() - z;
1795void KTextEditor::ViewPrivate::toggleInsert()
1797 doc()->
config()->setOvr(!doc()->config()->ovr());
1798 m_toggleInsert->setChecked(isOverwriteMode());
1801 if (isOverwriteMode()) {
1802 clearSecondaryCursors();
1805 Q_EMIT viewModeChanged(
this, viewMode());
1806 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1809void KTextEditor::ViewPrivate::slotSaveCanceled(
const QString &error)
1811 if (!
error.isEmpty()) {
1816void KTextEditor::ViewPrivate::gotoLine()
1818 gotoBar()->updateData();
1819 bottomViewBar()->showBarWidget(gotoBar());
1822void KTextEditor::ViewPrivate::changeDictionary()
1824 dictionaryBar()->updateData();
1825 bottomViewBar()->showBarWidget(dictionaryBar());
1828void KTextEditor::ViewPrivate::joinLines()
1830 int first = selectionRange().start().line();
1831 int last = selectionRange().end().line();
1833 if (first == last) {
1834 first = cursorPosition().line();
1846 setCursorPositionInternal(savedPosition);
1849 const int scroll = config.
readEntry(
"ScrollLine", -1);
1850 if (scroll >= 0 && scroll < doc()->lines() && savedPosition.
line() < doc()->lines()) {
1855 if (config.
hasKey(
"Dynamic Word Wrap")) {
1857 m_config->setDynWordWrap(config.
readEntry(
"Dynamic Word Wrap", m_config->global()->dynWordWrap()));
1862 applyFoldingState();
1864 m_forceRTL = config.
readEntry(
"Force RTL Direction",
false);
1865 m_forceRTLDirection->setChecked(m_forceRTL);
1867 for (
const auto &mode : m_viewInternal->m_inputModes) {
1868 mode->readSessionConfig(config);
1878 const auto cursor = cursorPosition();
1880 config.
writeEntry(
"CursorLine", cursor.line());
1881 config.
writeEntry(
"CursorColumn", cursor.column());
1885 const int scrollLine = firstDisplayedLineInternal(LineType::RealLine);
1886 if (scrollLine > 0 && scrollLine != cursor.line()) {
1891 if (m_config->isSet(KateViewConfig::DynamicWordWrap)) {
1892 config.
writeEntry(
"Dynamic Word Wrap", m_config->dynWordWrap());
1897 if (!m_savedFoldingState.object().value(
QLatin1String(
"ranges")).toArray().isEmpty()) {
1903 config.
writeEntry(
"Force RTL Direction", m_forceRTL);
1906 for (
const auto &mode : m_viewInternal->m_inputModes) {
1907 mode->writeSessionConfig(config);
1911int KTextEditor::ViewPrivate::getEol()
const
1913 return doc()->
config()->eol();
1916QMenu *KTextEditor::ViewPrivate::getEolMenu()
1918 return m_setEndOfLine->menu();
1921void KTextEditor::ViewPrivate::setEol(
int eol)
1923 if (!doc()->isReadWrite()) {
1927 if (m_updatingDocumentConfig) {
1931 if (eol != doc()->config()->eol()) {
1932 doc()->setModified(
true);
1933 doc()->
config()->setEol(eol);
1937void KTextEditor::ViewPrivate::setAddBom(
bool enabled)
1939 if (!doc()->isReadWrite()) {
1943 if (m_updatingDocumentConfig) {
1947 doc()->
config()->setBom(enabled);
1951void KTextEditor::ViewPrivate::setIconBorder(
bool enable)
1953 config()->setValue(KateViewConfig::ShowIconBar, enable);
1956void KTextEditor::ViewPrivate::toggleIconBorder()
1958 config()->setValue(KateViewConfig::ShowIconBar, !config()->iconBar());
1961void KTextEditor::ViewPrivate::setLineNumbersOn(
bool enable)
1963 config()->setValue(KateViewConfig::ShowLineNumbers, enable);
1966void KTextEditor::ViewPrivate::toggleLineNumbersOn()
1968 config()->setValue(KateViewConfig::ShowLineNumbers, !config()->lineNumbers());
1971void KTextEditor::ViewPrivate::setScrollBarMarks(
bool enable)
1973 config()->setValue(KateViewConfig::ShowScrollBarMarks, enable);
1976void KTextEditor::ViewPrivate::toggleScrollBarMarks()
1978 config()->setValue(KateViewConfig::ShowScrollBarMarks, !config()->scrollBarMarks());
1981void KTextEditor::ViewPrivate::setScrollBarMiniMap(
bool enable)
1983 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, enable);
1986void KTextEditor::ViewPrivate::toggleScrollBarMiniMap()
1988 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, !config()->scrollBarMiniMap());
1991void KTextEditor::ViewPrivate::setScrollBarMiniMapAll(
bool enable)
1993 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, enable);
1996void KTextEditor::ViewPrivate::toggleScrollBarMiniMapAll()
1998 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, !config()->scrollBarMiniMapAll());
2001void KTextEditor::ViewPrivate::setScrollBarMiniMapWidth(
int width)
2003 config()->setValue(KateViewConfig::ScrollBarMiniMapWidth, width);
2006void KTextEditor::ViewPrivate::toggleShowSpaces()
2008 if (m_updatingDocumentConfig) {
2012 using WhitespaceRendering = KateDocumentConfig::WhitespaceRendering;
2013 doc()->
config()->setShowSpaces(doc()->config()->showSpaces() != WhitespaceRendering::None ? WhitespaceRendering::None : WhitespaceRendering::All);
2016void KTextEditor::ViewPrivate::toggleDynWordWrap()
2018 config()->setDynWordWrap(!config()->dynWordWrap());
2021void KTextEditor::ViewPrivate::toggleWWMarker()
2023 m_renderer->config()->setWordWrapMarker(!m_renderer->config()->wordWrapMarker());
2026void KTextEditor::ViewPrivate::toggleNPSpaces()
2028 m_renderer->setShowNonPrintableSpaces(!m_renderer->showNonPrintableSpaces());
2029 m_viewInternal->update();
2032void KTextEditor::ViewPrivate::toggleWordCount(
bool on)
2034 config()->setShowWordCount(on);
2037void KTextEditor::ViewPrivate::setFoldingMarkersOn(
bool enable)
2039 config()->setValue(KateViewConfig::ShowFoldingBar, enable);
2042void KTextEditor::ViewPrivate::toggleFoldingMarkers()
2044 config()->setValue(KateViewConfig::ShowFoldingBar, !config()->foldingBar());
2047bool KTextEditor::ViewPrivate::iconBorder()
2049 return m_viewInternal->m_leftBorder->iconBorderOn();
2052bool KTextEditor::ViewPrivate::lineNumbersOn()
2054 return m_viewInternal->m_leftBorder->lineNumbersOn();
2057bool KTextEditor::ViewPrivate::scrollBarMarks()
2059 return m_viewInternal->m_lineScroll->showMarks();
2062bool KTextEditor::ViewPrivate::scrollBarMiniMap()
2064 return m_viewInternal->m_lineScroll->showMiniMap();
2067int KTextEditor::ViewPrivate::dynWrapIndicators()
2069 return m_viewInternal->m_leftBorder->dynWrapIndicators();
2072bool KTextEditor::ViewPrivate::foldingMarkersOn()
2074 return m_viewInternal->m_leftBorder->foldingMarkersOn();
2077bool KTextEditor::ViewPrivate::forceRTLDirection()
const
2082void KTextEditor::ViewPrivate::toggleWriteLock()
2084 doc()->setReadWrite(!doc()->isReadWrite());
2089 m_viewInternal->registerTextHintProvider(provider);
2094 m_viewInternal->unregisterTextHintProvider(provider);
2097void KTextEditor::ViewPrivate::setTextHintDelay(
int delay)
2099 m_viewInternal->setTextHintDelay(delay);
2102int KTextEditor::ViewPrivate::textHintDelay()
const
2104 return m_viewInternal->textHintDelay();
2108void KTextEditor::ViewPrivate::find()
2110 currentInputMode()->find();
2114void KTextEditor::ViewPrivate::findSelectedForwards()
2116 currentInputMode()->findSelectedForwards();
2120void KTextEditor::ViewPrivate::findSelectedBackwards()
2122 currentInputMode()->findSelectedBackwards();
2125void KTextEditor::ViewPrivate::skipCurrentOccurunceSelection()
2127 if (isMulticursorNotAllowed()) {
2130 m_skipCurrentSelection =
true;
2133void KTextEditor::ViewPrivate::findNextOccurunceAndSelect()
2135 if (isMulticursorNotAllowed()) {
2139 const auto text = selection() ? doc()->
text(selectionRange()) :
QString();
2140 if (text.isEmpty()) {
2141 const auto selection = doc()->
wordRangeAt(cursorPosition());
2143 setSelection(selection);
2144 setCursorPosition(selection.end());
2147 for (
auto &c : m_secondaryCursors) {
2148 const auto range = doc()->
wordRangeAt(c.cursor());
2149 if (!c.range && !c.anchor.isValid()) {
2150 c.anchor = range.
start();
2151 c.range.reset(newSecondarySelectionRange(range));
2157 }
else if (!m_rangesForHighlights.empty()) {
2162 const auto lastSelectionRange = selectionRange();
2167 searchRange.setRange(doc()->documentRange().
start(), lastSelectionRange.end());
2176 auto it = std::find_if(m_secondaryCursors.begin(), m_secondaryCursors.end(), [&](
const SecondaryCursor &c) {
2177 return c.range && c.range->toRange() == matches.constFirst();
2180 if (it != m_secondaryCursors.end()) {
2181 m_secondaryCursors.erase(it);
2187 setCursorPosition(matches.
constFirst().end());
2191 if (!m_skipCurrentSelection) {
2192 PlainSecondaryCursor c;
2193 c.pos = lastSelectionRange.end();
2194 c.range = lastSelectionRange;
2196 addSecondaryCursorsWithSelection({c});
2199 m_skipCurrentSelection =
false;
2202void KTextEditor::ViewPrivate::findAllOccuruncesAndSelect()
2204 if (isMulticursorNotAllowed()) {
2210 const auto selection = doc()->
wordRangeAt(cursorPosition());
2211 setSelection(selection);
2212 setCursorPosition(selection.end());
2214 text = doc()->
text(selection);
2216 for (
auto &c : m_secondaryCursors) {
2217 const auto range = doc()->
wordRangeAt(c.cursor());
2218 if (!c.range && !c.anchor.isValid()) {
2219 c.anchor = range.
start();
2220 c.range.reset(newSecondarySelectionRange(range));
2235 if (matches.
constFirst() != selectionRange()) {
2236 PlainSecondaryCursor c;
2241 searchRange.setStart(matches.
constFirst().end());
2243 }
while (matches.
first().isValid());
2246 if (!resultRanges.
empty()) {
2250 clearSecondaryCursors();
2251 addSecondaryCursorsWithSelection(resultRanges);
2255void KTextEditor::ViewPrivate::replace()
2257 currentInputMode()->findReplace();
2261void KTextEditor::ViewPrivate::findNext()
2263 currentInputMode()->findNext();
2267void KTextEditor::ViewPrivate::findPrevious()
2269 currentInputMode()->findPrevious();
2272void KTextEditor::ViewPrivate::showSearchWrappedHint(
bool isReverseSearch)
2275 const QIcon icon = isReverseSearch ?
QIcon::fromTheme(QStringLiteral(
"go-up-search")) :
QIcon::fromTheme(QStringLiteral(
"go-down-search"));
2277 if (!m_wrappedMessage || m_isLastSearchReversed != isReverseSearch) {
2278 m_isLastSearchReversed = isReverseSearch;
2280 m_wrappedMessage->setIcon(icon);
2282 m_wrappedMessage->setAutoHide(2000);
2284 m_wrappedMessage->setView(
this);
2289void KTextEditor::ViewPrivate::createMultiCursorsFromSelection()
2291 if (!selection() || selectionRange().isEmpty()) {
2296 clearSecondaryCursors();
2298 const auto range = selectionRange();
2302 const auto currentLine = cursorPosition().line();
2303 setCursorPosition({currentLine, doc()->
lineLength(currentLine)});
2304 for (
int line =
start; line <=
end; ++line) {
2305 if (line != currentLine) {
2311 setSecondaryCursors(cursorsToAdd);
2314void KTextEditor::ViewPrivate::removeCursorsFromEmptyLines()
2316 if (!m_secondaryCursors.empty()) {
2317 std::vector<KTextEditor::Cursor> cursorsToRemove;
2318 for (
const auto &c : m_secondaryCursors) {
2319 auto cursor = c.cursor();
2320 if (doc()->lineLength(cursor.line()) == 0) {
2321 cursorsToRemove.push_back(cursor);
2324 removeSecondaryCursors(cursorsToRemove);
2328void KTextEditor::ViewPrivate::slotSelectionChanged()
2330 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2331 m_deSelect->setEnabled(selection());
2332 m_copyHtmlAction->setEnabled(selection());
2335 selectionChangedForHighlights();
2337 if (doc()->readOnly()) {
2341 m_cut->setEnabled(selection() || m_config->smartCopyCut());
2342 m_screenshotSelection->setVisible(selection());
2343 m_screenshotSelection->setEnabled(selection());
2347void KTextEditor::ViewPrivate::switchToCmdLine()
2349 currentInputMode()->activateCommandLine();
2357KateRendererConfig *KTextEditor::ViewPrivate::rendererConfig()
2359 return m_renderer->config();
2362void KTextEditor::ViewPrivate::updateConfig()
2368 m_toggleShowSpace->setChecked(doc()->config()->showSpaces() != KateDocumentConfig::WhitespaceRendering::None);
2371 if (m_hasWrap != config()->dynWordWrap()) {
2372 m_hasWrap = config()->dynWordWrap();
2374 m_viewInternal->dynWrapChanged();
2376 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
2377 m_toggleDynWrap->setChecked(config()->dynWordWrap());
2380 m_viewInternal->m_leftBorder->setDynWrapIndicators(config()->dynWordWrapIndicators());
2381 m_setDynWrapIndicators->setCurrentItem(config()->dynWordWrapIndicators());
2384 m_viewInternal->m_leftBorder->setLineNumbersOn(config()->lineNumbers());
2385 m_toggleLineNumbers->setChecked(config()->lineNumbers());
2388 m_viewInternal->m_leftBorder->setIconBorderOn(config()->iconBar());
2389 m_toggleIconBar->setChecked(config()->iconBar());
2392 m_viewInternal->m_lineScroll->setShowMarks(config()->scrollBarMarks());
2393 m_toggleScrollBarMarks->setChecked(config()->scrollBarMarks());
2396 m_viewInternal->m_lineScroll->setShowMiniMap(config()->scrollBarMiniMap());
2397 m_toggleScrollBarMiniMap->setChecked(config()->scrollBarMiniMap());
2400 m_viewInternal->m_lineScroll->setMiniMapAll(config()->scrollBarMiniMapAll());
2404 m_viewInternal->m_lineScroll->setMiniMapWidth(config()->scrollBarMiniMapWidth());
2407 m_toggleBlockSelection->setChecked(blockSelection());
2408 m_toggleInsert->setChecked(isOverwriteMode());
2410 updateFoldingConfig();
2413 m_bookmarks->setSorting((KateBookmarks::Sorting)config()->bookmarkSort());
2415 m_viewInternal->setAutoCenterLines(config()->autoCenterLines());
2417 for (
const auto &input : m_viewInternal->m_inputModes) {
2418 input->updateConfig();
2421 setInputMode(config()->inputMode(),
false );
2423 reflectOnTheFlySpellCheckStatus(doc()->isOnTheFlySpellCheckingEnabled());
2426 bool wc = config()->wordCompletion();
2435 bool kc = config()->keywordCompletion();
2444 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
2445 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2447 m_accessibilityEnabled = m_config->value(KateViewConfig::EnableAccessibility).toBool();
2451 m_statusBar->updateStatus();
2455 m_viewInternal->cache()->clear();
2459 Q_EMIT configChanged(
this);
2462void KTextEditor::ViewPrivate::updateDocumentConfig()
2468 m_updatingDocumentConfig =
true;
2470 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
2472 m_addBom->setChecked(doc()->config()->
bom());
2474 m_updatingDocumentConfig =
false;
2477 ensureCursorColumnValid();
2480 m_renderer->setTabWidth(doc()->config()->tabWidth());
2481 m_renderer->setIndentWidth(doc()->config()->indentationWidth());
2484 m_viewInternal->cache()->clear();
2489void KTextEditor::ViewPrivate::updateRendererConfig()
2495 m_toggleWWMarker->setChecked(m_renderer->config()->wordWrapMarker());
2497 m_viewInternal->updateBracketMarkAttributes();
2498 m_viewInternal->updateBracketMarks();
2501 m_viewInternal->cache()->clear();
2503 m_viewInternal->updateView(
true);
2506 m_viewInternal->m_leftBorder->updateFont();
2507 m_viewInternal->m_leftBorder->repaint();
2509 m_viewInternal->m_lineScroll->queuePixmapUpdate();
2511 currentInputMode()->updateRendererConfig();
2515 Q_EMIT configChanged(
this);
2518void KTextEditor::ViewPrivate::updateFoldingConfig()
2521 m_viewInternal->m_leftBorder->setFoldingMarkersOn(config()->foldingBar());
2522 m_toggleFoldingMarkers->setChecked(config()->foldingBar());
2524 if (hasCommentInFirstLine(m_doc)) {
2525 if (config()->foldFirstLine() && !m_autoFoldedFirstLine) {
2527 m_autoFoldedFirstLine =
true;
2528 }
else if (!config()->foldFirstLine() && m_autoFoldedFirstLine) {
2530 m_autoFoldedFirstLine =
false;
2533 m_autoFoldedFirstLine =
false;
2539 QStringLiteral(
"folding_toplevel")
2540 , QStringLiteral(
"folding_expandtoplevel")
2541 , QStringLiteral(
"folding_toggle_current")
2542 , QStringLiteral(
"folding_toggle_in_current")
2546 for (
int z = 0; z < l.
size(); z++)
2547 if ((a = actionCollection()->action(l[z].toAscii().constData()))) {
2548 a->
setEnabled(doc()->highlight() && doc()->highlight()->allowsFolding());
2553void KTextEditor::ViewPrivate::ensureCursorColumnValid()
2560 if (!blockSelection() && wrapCursor() && (!c.
isValid() || c.
column() > doc()->lineLength(c.
line()))) {
2561 c.
setColumn(doc()->lineLength(cursorPosition().line()));
2562 setCursorPosition(c);
2567void KTextEditor::ViewPrivate::editStart()
2569 m_viewInternal->editStart();
2572void KTextEditor::ViewPrivate::editEnd(
int editTagLineStart,
int editTagLineEnd,
bool tagFrom)
2574 m_viewInternal->editEnd(editTagLineStart, editTagLineEnd, tagFrom);
2575 textFolding().editEnd(editTagLineStart, editTagLineEnd, [
this](
int line) {
2576 return m_doc->buffer().isFoldingStartingOnLine(line).first;
2582 m_viewInternal->editSetCursor(cursor);
2589 return m_viewInternal->tagLine(virtualCursor);
2594 return m_viewInternal->tagRange(range, realLines);
2599 return m_viewInternal->tagLines(lineRange.
start(), lineRange.
end(), realLines);
2604 return m_viewInternal->tagLines(
start, end, realCursors);
2607void KTextEditor::ViewPrivate::tagAll()
2609 m_viewInternal->tagAll();
2612void KTextEditor::ViewPrivate::clear()
2614 m_viewInternal->clear();
2617void KTextEditor::ViewPrivate::repaintText(
bool paintOnlyDirty)
2619 if (paintOnlyDirty) {
2620 m_viewInternal->updateDirty();
2622 m_viewInternal->update();
2626void KTextEditor::ViewPrivate::updateView(
bool changed)
2629 m_viewInternal->updateView(changed);
2630 m_viewInternal->m_leftBorder->update();
2635void KTextEditor::ViewPrivate::slotHlChanged()
2637 KateHighlighting *hl = doc()->highlight();
2638 bool ok(!hl->getCommentStart(0).
isEmpty() || !hl->getCommentSingleLineStart(0).
isEmpty());
2640 if (actionCollection()->action(QStringLiteral(
"tools_comment"))) {
2641 actionCollection()->action(QStringLiteral(
"tools_comment"))->setEnabled(ok);
2644 if (actionCollection()->action(QStringLiteral(
"tools_uncomment"))) {
2645 actionCollection()->action(QStringLiteral(
"tools_uncomment"))->setEnabled(ok);
2648 if (actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))) {
2649 actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))->setEnabled(ok);
2653 updateFoldingConfig();
2656int KTextEditor::ViewPrivate::virtualCursorColumn()
const
2658 return doc()->toVirtualColumn(m_viewInternal->cursorPosition());
2661void KTextEditor::ViewPrivate::notifyMousePositionChanged(
const KTextEditor::Cursor newPosition)
2663 Q_EMIT mousePositionChanged(
this, newPosition);
2671 if (selection == m_selection) {
2682 tagSelection(oldSelection);
2686 Q_EMIT selectionChanged(
this);
2692bool KTextEditor::ViewPrivate::clearSelection()
2694 return clearSelection(
true);
2697bool KTextEditor::ViewPrivate::clearSelection(
bool redraw,
bool finishedChangingSelection)
2711 tagSelection(oldSelection);
2717 if (finishedChangingSelection) {
2718 Q_EMIT selectionChanged(
this);
2721 m_viewInternal->m_selChangedByUser =
false;
2726bool KTextEditor::ViewPrivate::selection()
const
2728 if (!wrapCursor()) {
2731 return m_selection.toRange().isValid();
2735QString KTextEditor::ViewPrivate::selectionText()
const
2738 return doc()->
text(m_selection, blockSelect);
2742 for (
const auto &c : m_secondaryCursors) {
2747 ranges.
push_back(m_selection.toRange());
2748 std::sort(ranges.
begin(), ranges.
end());
2751 text.
reserve(ranges.
size() * m_selection.toRange().columnWidth());
2752 for (
int i = 0; i < ranges.
size() - 1; ++i) {
2753 text += doc()->
text(ranges[i]) + QStringLiteral(
"\n");
2755 text += doc()->
text(ranges.
last());
2760bool KTextEditor::ViewPrivate::removeSelectedText()
2762 if (!hasSelections()) {
2768 bool removed =
false;
2771 completionWidget()->setIgnoreBufferSignals(
true);
2772 for (
auto &c : m_secondaryCursors) {
2775 doc()->removeText(c.range->toRange());
2779 completionWidget()->setIgnoreBufferSignals(
false);
2787 doc()->removeText(selection, blockSelect);
2792 int selectionColumn = qMin(doc()->toVirtualColumn(selection.
start()), doc()->toVirtualColumn(selection.
end()));
2796 setSelection(newSelection);
2797 setCursorPositionInternal(newSelection.
start());
2799 clearSecondarySelections();
2800 clearSelection(
false);
2806bool KTextEditor::ViewPrivate::selectAll()
2808 clearSecondaryCursors();
2809 setBlockSelection(
false);
2816 setSelection(doc()->documentRange());
2817 m_viewInternal->moveCursorToSelectionEdge(
false);
2818 m_viewInternal->updateMicroFocus();
2825 if ((!blockSelect) && (ret.
column() < 0)) {
2830 return cursor.
line() >= m_selection.start().line() && ret.
line() <= m_selection.end().line() && ret.
column() >= m_selection.start().column()
2831 && ret.
column() <= m_selection.end().column();
2833 return m_selection.toRange().contains(cursor) || m_selection.end() == cursor;
2837bool KTextEditor::ViewPrivate::lineSelected(
int line)
2839 return !blockSelect && m_selection.toRange().containsLine(line);
2844 return (!blockSelect)
2845 && (lineEndPos.
line() > m_selection.start().line()
2846 || (lineEndPos.
line() == m_selection.start().line() && (m_selection.start().column() < lineEndPos.
column() || lineEndPos.
column() == -1)))
2847 && (lineEndPos.
line() < m_selection.end().line()
2848 || (lineEndPos.
line() == m_selection.end().line() && (lineEndPos.
column() <= m_selection.end().column() && lineEndPos.
column() != -1)));
2851bool KTextEditor::ViewPrivate::lineHasSelected(
int line)
2853 return selection() && m_selection.toRange().
containsLine(line);
2856bool KTextEditor::ViewPrivate::lineIsSelection(
int line)
2858 return (line == m_selection.start().line() && line == m_selection.end().line());
2864 if (oldSelection.
start().
line() == -1) {
2868 tagLines(m_selection,
true);
2870 }
else if (blockSelection()
2871 && (oldSelection.
start().
column() != m_selection.start().column() || oldSelection.
end().
column() != m_selection.end().column())) {
2873 tagLines(m_selection,
true);
2874 tagLines(oldSelection,
true);
2877 if (oldSelection.
start() != m_selection.
start()) {
2881 if (oldSelection.
end() != m_selection.end()) {
2888 tagLines(oldSelection,
true);
2894 setSelection(doc()->wordRangeAt(cursor));
2899 int line = cursor.
line();
2900 if (line + 1 >= doc()->lines()) {
2907void KTextEditor::ViewPrivate::cut()
2909 if (!selection() && !m_config->smartCopyCut()) {
2915 m_markedSelection =
false;
2919 selectLine(cursorPosition());
2921 removeSelectedText();
2924void KTextEditor::ViewPrivate::copy()
2930 if (!m_config->smartCopyCut()) {
2934 m_viewInternal->moveEdge(KateViewInternal::left,
false);
2936 text = selectionText();
2939 if (!m_secondaryCursors.empty()) {
2941 for (
const auto &c : m_secondaryCursors) {
2946 ranges.
push_back(m_selection.toRange());
2947 std::sort(ranges.
begin(), ranges.
end());
2949 for (
auto range : ranges) {
2950 texts.
append(doc()->text(range));
2955 if (m_markedSelection) {
2957 m_markedSelection =
false;
2965void KTextEditor::ViewPrivate::screenshot()
2971 ScreenshotDialog d(selectionRange(),
this);
2972 d.renderScreenshot(m_renderer);
2976void KTextEditor::ViewPrivate::pasteSelection()
2978 m_temporaryAutomaticInvocationDisabled =
true;
2980 m_temporaryAutomaticInvocationDisabled =
false;
2983void KTextEditor::ViewPrivate::swapWithClipboard()
2985 m_temporaryAutomaticInvocationDisabled =
true;
2994 doc()->paste(
this, text);
2996 m_temporaryAutomaticInvocationDisabled =
false;
2999void KTextEditor::ViewPrivate::applyWordWrap()
3001 int first = selectionRange().start().line();
3002 int last = selectionRange().end().line();
3004 if (first == last) {
3006 first = cursorPosition().line();
3017bool KTextEditor::ViewPrivate::blockSelection()
const
3022bool KTextEditor::ViewPrivate::setBlockSelection(
bool on)
3024 if (on != blockSelect) {
3029 const bool hadSelection = clearSelection(
false,
false);
3031 setSelection(oldSelection);
3033 m_toggleBlockSelection->setChecked(blockSelection());
3037 ensureCursorColumnValid();
3039 if (!hadSelection) {
3044 Q_EMIT selectionChanged(
this);
3051bool KTextEditor::ViewPrivate::toggleBlockSelection()
3054 clearSecondaryCursors();
3056 m_toggleBlockSelection->setChecked(!blockSelect);
3057 return setBlockSelection(!blockSelect);
3060bool KTextEditor::ViewPrivate::wrapCursor()
const
3062 return !blockSelection();
3069 Q_EMIT textInserted(view, position, text);
3075 if (templateString.
isEmpty()) {
3080 if (!doc()->isReadWrite()) {
3086 doc()->setActiveTemplateHandler(
nullptr);
3087 doc()->setActiveTemplateHandler(
new KateTemplateHandler(
this, c, templateString, script, doc()->undoManager()));
3093 return tagLines(range.
start(), range.
end(), realRange);
3096void KTextEditor::ViewPrivate::deactivateEditActions()
3098 for (
QAction *action : std::as_const(m_editActions)) {
3099 action->setEnabled(
false);
3103void KTextEditor::ViewPrivate::activateEditActions()
3105 for (
QAction *action : std::as_const(m_editActions)) {
3106 action->setEnabled(
true);
3110bool KTextEditor::ViewPrivate::mouseTrackingEnabled()
const
3116bool KTextEditor::ViewPrivate::setMouseTrackingEnabled(
bool)
3122bool KTextEditor::ViewPrivate::isMulticursorNotAllowed()
const
3129 auto primaryCursor = cursorPosition();
3130 const bool overlapsOrOnPrimary = pos == primaryCursor || (selection() && selectionRange().
contains(pos));
3131 if (overlapsOrOnPrimary && m_secondaryCursors.empty()) {
3135 }
else if (overlapsOrOnPrimary) {
3139 auto &last = m_secondaryCursors.back();
3140 setCursorPosition(last.cursor());
3142 setSelection(last.range->toRange());
3143 Q_ASSERT(last.anchor.isValid());
3144 m_viewInternal->m_selectAnchor = last.anchor;
3146 m_secondaryCursors.pop_back();
3153 if (removeSecondaryCursors({pos},
true)) {
3161 setCursorPosition(pos);
3162 KTextEditor::ViewPrivate::PlainSecondaryCursor p;
3163 p.pos = primaryCursor;
3166 addSecondaryCursorsWithSelection({p});
3171 clearSecondaryCursors();
3173 if (positions.
isEmpty() || isMulticursorNotAllowed()) {
3177 const auto totalLines = doc()->
lines();
3178 for (
auto p : positions) {
3179 if (p != cursorPosition() && p.line() < totalLines) {
3182 m_secondaryCursors.push_back(std::move(c));
3190void KTextEditor::ViewPrivate::clearSecondarySelections()
3192 for (
auto &c : m_secondaryCursors) {
3198void KTextEditor::ViewPrivate::clearSecondaryCursors()
3200 if (m_secondaryCursors.empty()) {
3203 for (
const auto &c : m_secondaryCursors) {
3204 tagLine(c.cursor());
3206 m_secondaryCursors.clear();
3207 m_viewInternal->updateDirty();
3210const std::vector<KTextEditor::ViewPrivate::SecondaryCursor> &KTextEditor::ViewPrivate::secondaryCursors()
const
3212 return m_secondaryCursors;
3218 cursors.
reserve(m_secondaryCursors.size());
3219 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(cursors), [](
const SecondaryCursor &c) {
3221 return PlainSecondaryCursor{.pos=c.cursor(), .range=c.range->toRange()};
3223 return PlainSecondaryCursor{.pos=c.cursor(), .range=KTextEditor::Range::invalid()};
3228bool KTextEditor::ViewPrivate::removeSecondaryCursors(
const std::vector<KTextEditor::Cursor> &cursorsToRemove,
bool removeIfOverlapsSelection)
3230 Q_ASSERT(std::is_sorted(cursorsToRemove.begin(), cursorsToRemove.end()));
3234 if (removeIfOverlapsSelection) {
3235 m_secondaryCursors.
erase(std::remove_if(m_secondaryCursors.begin(),
3236 m_secondaryCursors.end(),
3237 [&](
const SecondaryCursor &c) {
3238 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3239 return c.cursor() == pos || (c.range && c.range->contains(pos));
3241 const bool match = it != cursorsToRemove.end();
3247 m_secondaryCursors.end());
3249 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3250 m_secondaryCursors.end(),
3251 [&](
const SecondaryCursor &c) {
3252 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](
KTextEditor::Cursor pos) {
3253 return c.cursor() == pos;
3255 const bool match = it != cursorsToRemove.end();
3261 m_secondaryCursors.end());
3264 for (
const auto &c : linesToTag) {
3265 tagLine(m_viewInternal->toVirtualCursor(c));
3267 return !linesToTag.
empty();
3269 for (
auto cur : cursorsToRemove) {
3270 auto &sec = m_secondaryCursors;
3271 auto it = std::find_if(sec.begin(), sec.end(), [cur](
const SecondaryCursor &c) {
3272 return c.cursor() == cur;
3274 if (it != sec.end()) {
3276 m_secondaryCursors.erase(it);
3277 tagLine(m_viewInternal->toVirtualCursor(cur));
3282 m_viewInternal->updateDirty();
3284 m_viewInternal->paintCursor();
3286 return !linesToTag.
empty();
3291void KTextEditor::ViewPrivate::ensureUniqueCursors(
bool matchLine)
3293 if (m_secondaryCursors.empty()) {
3297 std::vector<SecondaryCursor>::iterator it;
3299 auto matchLine = [](
const SecondaryCursor &l,
const SecondaryCursor &r) {
3300 return l.cursor().line() == r.cursor().line();
3302 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end(), matchLine);
3304 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end());
3306 if (it != m_secondaryCursors.end()) {
3307 m_secondaryCursors.erase(it, m_secondaryCursors.end());
3311 const int ln = cursorPosition().line();
3312 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3313 m_secondaryCursors.end(),
3314 [ln](
const SecondaryCursor &c) {
3315 return c.cursor().line() == ln;
3317 m_secondaryCursors.end());
3319 const auto cp = cursorPosition();
3320 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3321 m_secondaryCursors.end(),
3322 [cp](
const SecondaryCursor &c) {
3323 return c.cursor() == cp;
3325 m_secondaryCursors.end());
3331 if (isMulticursorNotAllowed() || cursorsWithSelection.
isEmpty()) {
3335 for (
const auto &c : cursorsWithSelection) {
3337 if (c.pos == cursorPosition()) {
3341 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c.pos)));
3342 if (c.range.isValid()) {
3343 n.range.reset(newSecondarySelectionRange(c.range));
3344 n.anchor = c.range.start() == c.pos ? c.range.end() : c.range.start();
3346 m_secondaryCursors.push_back(std::move(n));
3355 auto range =
new Kate::TextRange(doc()->buffer(), selRange, expandBehaviour);
3360 selAttr->setBackground(color);
3362 range->setZDepth(-999999.);
3363 range->setAttribute(selAttr);
3367bool KTextEditor::ViewPrivate::hasSelections()
const
3371 return std::any_of(m_secondaryCursors.cbegin(), m_secondaryCursors.cend(), [](
const SecondaryCursor &c) {
3372 return c.range && !c.range->isEmpty();
3376void KTextEditor::ViewPrivate::addSecondaryCursorDown()
3379 const auto &secondary = secondaryCursors();
3380 if (!secondary.empty()) {
3381 last = secondary.back().cursor();
3382 last = std::max(cursorPosition(), last);
3384 if (last.
line() >= doc()->lastLine()) {
3388 auto nextRange = m_viewInternal->nextLayout(last);
3389 if (!nextRange.isValid()) {
3392 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3393 if (!primaryCursorLineLayout.isValid()) {
3397 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3398 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3399 addSecondaryCursor(next);
3402void KTextEditor::ViewPrivate::addSecondaryCursorUp()
3405 const auto &secondary = secondaryCursors();
3406 if (!secondary.empty()) {
3407 last = secondary.front().cursor();
3408 last = std::min(cursorPosition(), last);
3410 if (last.
line() == 0) {
3413 auto nextRange = m_viewInternal->previousLayout(last);
3414 if (!nextRange.isValid()) {
3418 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3419 if (!primaryCursorLineLayout.isValid()) {
3423 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3424 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3425 addSecondaryCursor(next);
3431 ret.
reserve(m_secondaryCursors.size() + 1);
3432 ret << cursorPosition();
3433 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3446 ret.
reserve(m_secondaryCursors.size() + 1);
3447 ret << selectionRange();
3448 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3450 qWarning() <<
"selectionRanges(): Unexpected null selection range, please fix";
3451 return KTextEditor::Range::invalid();
3453 return c.range->toRange();
3460 if (isMulticursorNotAllowed()) {
3461 qWarning() <<
"setCursors failed: Multicursors not allowed because one of the following is true"
3462 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3467 clearSecondaryCursors();
3468 if (cursorPositions.
empty()) {
3472 const auto primary = cursorPositions.
front();
3476 setCursorPosition(primary);
3478 setSecondaryCursors(cursorPositions);
3483 if (isMulticursorNotAllowed()) {
3484 qWarning() <<
"setSelections failed: Multicursors not allowed because one of the following is true"
3485 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3490 clearSecondaryCursors();
3492 if (selectionRanges.
isEmpty()) {
3496 auto first = selectionRanges.
front();
3497 setCursorPosition(first.end());
3498 setSelection(first);
3500 if (selectionRanges.
size() == 1) {
3505 for (
auto it = selectionRanges.
begin() + 1; it != selectionRanges.
end(); ++it) {
3508 if (c == cursorPosition() || !r.
isValid() || r.
isEmpty() || !docRange.contains(r)) {
3514 n.range.reset(newSecondarySelectionRange(r));
3515 n.anchor = r.
start();
3516 m_secondaryCursors.push_back(std::move(n));
3518 m_viewInternal->mergeSelections();
3524void KTextEditor::ViewPrivate::sortCursors()
3526 std::sort(m_secondaryCursors.begin(), m_secondaryCursors.end());
3527 ensureUniqueCursors();
3530void KTextEditor::ViewPrivate::paintCursors()
3532 if (m_viewInternal->m_cursorTimer.isActive()) {
3536 renderer()->setDrawCaret(
true);
3538 m_viewInternal->paintCursor();
3541bool KTextEditor::ViewPrivate::isCompletionActive()
const
3543 return completionWidget()->isCompletionActive();
3548 if (!m_completionWidget) {
3552 return m_completionWidget;
3557 completionWidget()->startCompletion(word, model);
3560void KTextEditor::ViewPrivate::startCompletion(
const Range &word,
3562 KTextEditor::CodeCompletionModel::InvocationType invocationType)
3564 completionWidget()->startCompletion(word, models, invocationType);
3567void KTextEditor::ViewPrivate::abortCompletion()
3569 completionWidget()->abortCompletion();
3572void KTextEditor::ViewPrivate::forceCompletion()
3574 completionWidget()->execute();
3579 completionWidget()->registerCompletionModel(model);
3584 completionWidget()->unregisterCompletionModel(model);
3589 return completionWidget()->isCompletionModelRegistered(model);
3594 return completionWidget()->codeCompletionModels();
3597bool KTextEditor::ViewPrivate::isAutomaticInvocationEnabled()
const
3599 return !m_temporaryAutomaticInvocationDisabled && m_config->automaticCompletionInvocation();
3602void KTextEditor::ViewPrivate::setAutomaticInvocationEnabled(
bool enabled)
3604 config()->setValue(KateViewConfig::AutomaticCompletionInvocation, enabled);
3609 Q_EMIT completionExecuted(
this, position, model, index);
3612void KTextEditor::ViewPrivate::sendCompletionAborted()
3614 Q_EMIT completionAborted(
this);
3617void KTextEditor::ViewPrivate::paste(
const QString *textToPaste)
3619 const int cursorCount = m_secondaryCursors.size() + 1;
3621 if (cursorCount == multicursorClipboard.size() && !textToPaste) {
3622 if (doc()->multiPaste(
this, multicursorClipboard)) {
3625 }
else if (!textToPaste && cursorCount > 1) {
3631 for (
int i = 0; i < cursorCount; ++i) {
3636 if (doc()->multiPaste(
this, texts)) {
3641 m_temporaryAutomaticInvocationDisabled =
true;
3643 m_temporaryAutomaticInvocationDisabled =
false;
3648 return setCursorPositionInternal(position, 1,
true);
3653 return m_viewInternal->cursorPosition();
3658 return KTextEditor::Cursor(m_viewInternal->cursorPosition().line(), virtualCursorColumn());
3664 const QPoint pt = m_viewInternal->cursorToCoordinate(cursor,
true,
false);
3665 return pt ==
QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3671 return m_viewInternal->coordinatesToCursor(m_viewInternal->mapFromParent(coords),
false);
3674QPoint KTextEditor::ViewPrivate::cursorPositionCoordinates()
const
3677 const QPoint pt = m_viewInternal->cursorCoordinates(
false);
3678 return pt ==
QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3683 m_viewInternal->scrollPos(cursor,
false,
true,
false);
3686void KTextEditor::ViewPrivate::setHorizontalScrollPositionInternal(
int x)
3688 m_viewInternal->scrollColumns(x);
3693 return m_viewInternal->maxStartPos(
true);
3696int KTextEditor::ViewPrivate::firstDisplayedLineInternal(LineType lineType)
const
3698 if (lineType == RealLine) {
3699 return m_textFolding.visibleLineToLine(m_viewInternal->startLine());
3701 return m_viewInternal->startLine();
3705int KTextEditor::ViewPrivate::lastDisplayedLineInternal(LineType lineType)
const
3707 if (lineType == RealLine) {
3708 return m_textFolding.visibleLineToLine(m_viewInternal->endLine());
3710 return m_viewInternal->endLine();
3714QRect KTextEditor::ViewPrivate::textAreaRectInternal()
const
3716 const auto sourceRect = m_viewInternal->rect();
3717 const auto topLeft = m_viewInternal->mapTo(
this, sourceRect.topLeft());
3718 const auto bottomRight = m_viewInternal->mapTo(
this, sourceRect.bottomRight());
3719 return {topLeft, bottomRight};
3724 return setCursorPositionInternal(position, doc()->config()->tabWidth(),
true);
3727QScrollBar *KTextEditor::ViewPrivate::verticalScrollBar()
const
3729 return m_viewInternal->m_lineScroll;
3732QScrollBar *KTextEditor::ViewPrivate::horizontalScrollBar()
const
3734 return m_viewInternal->m_columnScroll;
3737bool KTextEditor::ViewPrivate::isLineRTL(
int line)
const
3741 int line = cursorPosition().line();
3743 const int count = doc()->
lines();
3744 for (
int i = 1; i < count; ++i) {
3752 int line = cursorPosition().line();
3753 for (; line >= 0; --line) {
3769 KateLineLayout *thisLine = m_viewInternal->cache()->line(pos.
line());
3770 return thisLine && thisLine->isValid() ? thisLine->layout() :
nullptr;
3773void KTextEditor::ViewPrivate::indent()
3777 doc()->indent(r, 1);
3780void KTextEditor::ViewPrivate::unIndent()
3784 doc()->indent(r, -1);
3787void KTextEditor::ViewPrivate::cleanIndent()
3791 doc()->indent(r, 0);
3794void KTextEditor::ViewPrivate::formatIndent()
3797 const int line = cursorPosition().line();
3800 formatRange = selectionRange();
3803 doc()->align(
this, formatRange);
3807void KTextEditor::ViewPrivate::align()
3812void KTextEditor::ViewPrivate::alignOn()
3819 range = selectionRange();
3826 doc()->alignOn(range, pattern, this->blockSelection());
3829void KTextEditor::ViewPrivate::comment()
3832 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::Comment);
3836void KTextEditor::ViewPrivate::uncomment()
3838 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::UnComment);
3841void KTextEditor::ViewPrivate::toggleComment()
3844 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::ToggleComment);
3848void KTextEditor::ViewPrivate::uppercase()
3850 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Uppercase);
3853void KTextEditor::ViewPrivate::killLine()
3855 std::vector<int> linesToRemove;
3856 if (m_selection.isEmpty()) {
3858 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3859 for (
const auto &c : m_secondaryCursors) {
3860 linesToRemove.push_back(c.pos->
line());
3863 linesToRemove.push_back(cursorPosition().line());
3865 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3866 for (
const auto &c : m_secondaryCursors) {
3867 const auto &range = c.range;
3871 for (
int line = range->
end().
line(); line >= range->
start().
line(); line--) {
3872 linesToRemove.push_back(line);
3877 for (
int line = m_selection.end().line(), endLine = m_selection.start().line(); line >= endLine; line--) {
3878 linesToRemove.push_back(line);
3882 std::sort(linesToRemove.begin(), linesToRemove.end(), std::greater{});
3883 linesToRemove.erase(std::unique(linesToRemove.begin(), linesToRemove.end()), linesToRemove.end());
3886 std::for_each(linesToRemove.begin(), linesToRemove.end(), [
this](
int line) {
3887 doc()->removeLine(line);
3891 ensureUniqueCursors();
3894void KTextEditor::ViewPrivate::lowercase()
3896 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
3899void KTextEditor::ViewPrivate::capitalize()
3902 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
3903 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Capitalize);
3907void KTextEditor::ViewPrivate::keyReturn()
3909 doc()->newLine(
this);
3910 m_viewInternal->iconBorder()->updateForCursorLineChange();
3911 m_viewInternal->updateView();
3914void KTextEditor::ViewPrivate::smartNewline()
3917 const int ln = cursor.
line();
3932 m_viewInternal->updateView();
3935void KTextEditor::ViewPrivate::noIndentNewline()
3937 doc()->newLine(
this, KTextEditor::DocumentPrivate::NoIndent);
3938 m_viewInternal->iconBorder()->updateForCursorLineChange();
3939 m_viewInternal->updateView();
3942void KTextEditor::ViewPrivate::newLineAbove()
3944 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Above);
3945 m_viewInternal->iconBorder()->updateForCursorLineChange();
3946 m_viewInternal->updateView();
3949void KTextEditor::ViewPrivate::newLineBelow()
3951 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Below);
3952 m_viewInternal->iconBorder()->updateForCursorLineChange();
3953 m_viewInternal->updateView();
3956void KTextEditor::ViewPrivate::backspace()
3959 doc()->backspace(
this);
3962void KTextEditor::ViewPrivate::insertTab()
3964 doc()->insertTab(
this, cursorPosition());
3967void KTextEditor::ViewPrivate::deleteWordLeft()
3970 m_viewInternal->wordPrev(
true);
3972 removeSelectedText();
3975 ensureUniqueCursors();
3977 m_viewInternal->tagRange(selection,
true);
3978 m_viewInternal->updateDirty();
3981void KTextEditor::ViewPrivate::keyDelete()
3989 selection = {selection.
start(),
end};
3990 doc()->removeText(selection, blockSelect);
3997 if (removeSelectedText()) {
4001 for (
const auto &c : m_secondaryCursors) {
4003 doc()->removeText(c.range->toRange());
4005 doc()->del(
this, c.cursor());
4010 doc()->del(
this, cursorPosition());
4012 ensureUniqueCursors();
4015void KTextEditor::ViewPrivate::deleteWordRight()
4018 m_viewInternal->wordNext(
true);
4020 removeSelectedText();
4023 ensureUniqueCursors();
4025 m_viewInternal->tagRange(selection,
true);
4026 m_viewInternal->updateDirty();
4029void KTextEditor::ViewPrivate::transpose()
4032 for (
const auto &c : m_secondaryCursors) {
4033 doc()->transpose(c.cursor());
4035 doc()->transpose(cursorPosition());
4039void KTextEditor::ViewPrivate::transposeWord()
4048 for (
const QChar &character : word) {
4049 if (character.isLetterOrNumber()) {
4056 if (wordIsInvalid(doc()->text(firstWord))) {
4060 setCursorPosition(firstWord.
end());
4065 setCursorPosition(firstWord.
start());
4067 curPos = cursorPosition();
4070 setCursorPosition(originalCurPos);
4075 if (wordIsInvalid(doc()->wordAt(curPos))) {
4076 setCursorPosition(originalCurPos);
4081 doc()->swapTextRanges(firstWord, secondWord);
4085 const int offsetFromWordEnd = firstWord.
end().
column() - originalCurPos.
column();
4089void KTextEditor::ViewPrivate::cursorLeft()
4091 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4092 if (isLineRTL(cursorPosition().line())) {
4093 m_viewInternal->updateCursor(selectionRange().
end());
4096 m_viewInternal->updateCursor(selectionRange().
start());
4100 for (
const auto &c : m_secondaryCursors) {
4104 const bool rtl = isLineRTL(c.cursor().
line());
4107 clearSecondarySelections();
4109 if (isLineRTL(cursorPosition().line())) {
4110 m_viewInternal->cursorNextChar(m_markedSelection);
4112 m_viewInternal->cursorPrevChar(m_markedSelection);
4117void KTextEditor::ViewPrivate::shiftCursorLeft()
4119 if (isLineRTL(cursorPosition().line())) {
4120 m_viewInternal->cursorNextChar(
true);
4122 m_viewInternal->cursorPrevChar(
true);
4126void KTextEditor::ViewPrivate::cursorRight()
4128 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4129 if (isLineRTL(cursorPosition().line())) {
4130 m_viewInternal->updateCursor(selectionRange().
start());
4133 m_viewInternal->updateCursor(selectionRange().
end());
4137 for (
const auto &c : m_secondaryCursors) {
4144 clearSecondarySelections();
4146 if (isLineRTL(cursorPosition().line())) {
4147 m_viewInternal->cursorPrevChar(m_markedSelection);
4149 m_viewInternal->cursorNextChar(m_markedSelection);
4154void KTextEditor::ViewPrivate::shiftCursorRight()
4156 if (isLineRTL(cursorPosition().line())) {
4157 m_viewInternal->cursorPrevChar(
true);
4159 m_viewInternal->cursorNextChar(
true);
4163void KTextEditor::ViewPrivate::wordLeft()
4165 if (isLineRTL(cursorPosition().line())) {
4166 m_viewInternal->wordNext(m_markedSelection);
4168 m_viewInternal->wordPrev(m_markedSelection);
4172void KTextEditor::ViewPrivate::shiftWordLeft()
4174 if (isLineRTL(cursorPosition().line())) {
4175 m_viewInternal->wordNext(
true);
4177 m_viewInternal->wordPrev(
true);
4181void KTextEditor::ViewPrivate::wordRight()
4183 if (isLineRTL(cursorPosition().line())) {
4184 m_viewInternal->wordPrev(m_markedSelection);
4186 m_viewInternal->wordNext(m_markedSelection);
4190void KTextEditor::ViewPrivate::shiftWordRight()
4192 if (isLineRTL(cursorPosition().line())) {
4193 m_viewInternal->wordPrev(
true);
4195 m_viewInternal->wordNext(
true);
4199void KTextEditor::ViewPrivate::markSelection()
4201 if (m_markedSelection && selection()) {
4203 clearSecondarySelections();
4205 m_markedSelection = !m_markedSelection;
4209void KTextEditor::ViewPrivate::home()
4211 m_viewInternal->home(m_markedSelection);
4214void KTextEditor::ViewPrivate::shiftHome()
4216 m_viewInternal->home(
true);
4219void KTextEditor::ViewPrivate::end()
4221 m_viewInternal->end(m_markedSelection);
4224void KTextEditor::ViewPrivate::shiftEnd()
4226 m_viewInternal->end(
true);
4229void KTextEditor::ViewPrivate::up()
4231 m_viewInternal->cursorUp(m_markedSelection);
4234void KTextEditor::ViewPrivate::shiftUp()
4236 m_viewInternal->cursorUp(
true);
4239void KTextEditor::ViewPrivate::down()
4241 m_viewInternal->cursorDown(m_markedSelection);
4244void KTextEditor::ViewPrivate::shiftDown()
4246 m_viewInternal->cursorDown(
true);
4249void KTextEditor::ViewPrivate::scrollUp()
4251 m_viewInternal->scrollUp();
4254void KTextEditor::ViewPrivate::scrollDown()
4256 m_viewInternal->scrollDown();
4259void KTextEditor::ViewPrivate::topOfView()
4261 m_viewInternal->topOfView();
4264void KTextEditor::ViewPrivate::shiftTopOfView()
4266 m_viewInternal->topOfView(
true);
4269void KTextEditor::ViewPrivate::bottomOfView()
4271 m_viewInternal->bottomOfView();
4274void KTextEditor::ViewPrivate::shiftBottomOfView()
4276 m_viewInternal->bottomOfView(
true);
4279void KTextEditor::ViewPrivate::pageUp()
4281 m_viewInternal->pageUp(m_markedSelection);
4284void KTextEditor::ViewPrivate::shiftPageUp()
4286 m_viewInternal->pageUp(
true);
4289void KTextEditor::ViewPrivate::pageDown()
4291 m_viewInternal->pageDown(m_markedSelection);
4294void KTextEditor::ViewPrivate::shiftPageDown()
4296 m_viewInternal->pageDown(
true);
4299void KTextEditor::ViewPrivate::top()
4301 m_viewInternal->top_home(m_markedSelection);
4304void KTextEditor::ViewPrivate::shiftTop()
4306 m_viewInternal->top_home(
true);
4309void KTextEditor::ViewPrivate::bottom()
4311 m_viewInternal->bottom_end(m_markedSelection);
4314void KTextEditor::ViewPrivate::shiftBottom()
4316 m_viewInternal->bottom_end(
true);
4319void KTextEditor::ViewPrivate::toMatchingBracket()
4321 m_viewInternal->cursorToMatchingBracket();
4324void KTextEditor::ViewPrivate::shiftToMatchingBracket()
4326 m_viewInternal->cursorToMatchingBracket(
true);
4329void KTextEditor::ViewPrivate::toPrevModifiedLine()
4331 const int startLine = cursorPosition().line() - 1;
4335 m_viewInternal->updateSelection(c,
false);
4336 m_viewInternal->updateCursor(c);
4340void KTextEditor::ViewPrivate::toNextModifiedLine()
4342 const int startLine = cursorPosition().line() + 1;
4346 m_viewInternal->updateSelection(c,
false);
4347 m_viewInternal->updateCursor(c);
4361void KTextEditor::ViewPrivate::setContextMenu(
QMenu *menu)
4363 if (m_contextMenu) {
4364 disconnect(m_contextMenu.data(), &
QMenu::aboutToShow,
this, &KTextEditor::ViewPrivate::aboutToShowContextMenu);
4365 disconnect(m_contextMenu.data(), &
QMenu::aboutToHide,
this, &KTextEditor::ViewPrivate::aboutToHideContextMenu);
4367 m_contextMenu = menu;
4368 m_userContextMenuSet =
true;
4370 if (m_contextMenu) {
4376QMenu *KTextEditor::ViewPrivate::contextMenu()
const
4378 if (m_userContextMenuSet) {
4379 return m_contextMenu;
4381 KXMLGUIClient *client =
const_cast<KTextEditor::ViewPrivate *
>(
this);
4389 for (
QWidget *w : menuContainers) {
4390 if (w->objectName() ==
QLatin1String(
"ktexteditor_popup")) {
4410QMenu *KTextEditor::ViewPrivate::defaultContextMenu(
QMenu *menu)
const
4413 menu =
new QMenu(
const_cast<KTextEditor::ViewPrivate *
>(
this));
4427 if (m_pasteSelection) {
4436 QAction *editing = actionCollection()->action(QStringLiteral(
"tools_scripts_Editing"));
4440 if (
QAction *spellingSuggestions = actionCollection()->action(QStringLiteral(
"spelling_suggestions"))) {
4444 if (
QAction *bookmark = actionCollection()->action(QStringLiteral(
"bookmarks"))) {
4452void KTextEditor::ViewPrivate::aboutToShowContextMenu()
4454 QMenu *menu = qobject_cast<QMenu *>(sender());
4457 Q_EMIT contextMenuAboutToShow(
this, menu);
4461void KTextEditor::ViewPrivate::aboutToHideContextMenu()
4463 m_spellingMenu->cleanUpAfterShown();
4467QStringList KTextEditor::ViewPrivate::configKeys()
const
4469 static const QStringList keys = {QStringLiteral(
"icon-bar"),
4470 QStringLiteral(
"line-numbers"),
4471 QStringLiteral(
"dynamic-word-wrap"),
4472 QStringLiteral(
"background-color"),
4473 QStringLiteral(
"selection-color"),
4474 QStringLiteral(
"search-highlight-color"),
4475 QStringLiteral(
"replace-highlight-color"),
4476 QStringLiteral(
"default-mark-type"),
4477 QStringLiteral(
"allow-mark-menu"),
4478 QStringLiteral(
"folding-bar"),
4479 QStringLiteral(
"folding-preview"),
4480 QStringLiteral(
"icon-border-color"),
4481 QStringLiteral(
"folding-marker-color"),
4482 QStringLiteral(
"line-number-color"),
4483 QStringLiteral(
"current-line-number-color"),
4484 QStringLiteral(
"modification-markers"),
4485 QStringLiteral(
"keyword-completion"),
4486 QStringLiteral(
"word-count"),
4487 QStringLiteral(
"line-count"),
4488 QStringLiteral(
"scrollbar-minimap"),
4489 QStringLiteral(
"scrollbar-preview"),
4490 QStringLiteral(
"font"),
4491 QStringLiteral(
"theme")};
4498 return config()->iconBar();
4500 return config()->lineNumbers();
4502 return config()->dynWordWrap();
4504 return rendererConfig()->backgroundColor();
4506 return rendererConfig()->selectionColor();
4507 }
else if (key ==
QLatin1String(
"search-highlight-color")) {
4508 return rendererConfig()->searchHighlightColor();
4509 }
else if (key ==
QLatin1String(
"replace-highlight-color")) {
4510 return rendererConfig()->replaceHighlightColor();
4512 return config()->defaultMarkType();
4514 return config()->allowMarkMenu();
4516 return config()->foldingBar();
4518 return config()->foldingPreview();
4520 return rendererConfig()->iconBarColor();
4522 return rendererConfig()->foldingColor();
4524 return rendererConfig()->lineNumberColor();
4525 }
else if (key ==
QLatin1String(
"current-line-number-color")) {
4526 return rendererConfig()->currentLineNumberColor();
4528 return config()->lineModification();
4530 return config()->keywordCompletion();
4532 return config()->showWordCount();
4534 return config()->showLineCount();
4536 return config()->scrollBarMiniMap();
4538 return config()->scrollBarPreview();
4540 return rendererConfig()->baseFont();
4542 return rendererConfig()->schema();
4549void KTextEditor::ViewPrivate::setConfigValue(
const QString &key,
const QVariant &value)
4552 if (config()->setValue(key, value)) {
4555 }
else if (rendererConfig()->setValue(key, value)) {
4562 rendererConfig()->setBackgroundColor(value.
value<
QColor>());
4564 rendererConfig()->setSelectionColor(value.
value<
QColor>());
4565 }
else if (key ==
QLatin1String(
"search-highlight-color")) {
4566 rendererConfig()->setSearchHighlightColor(value.
value<
QColor>());
4567 }
else if (key ==
QLatin1String(
"replace-highlight-color")) {
4568 rendererConfig()->setReplaceHighlightColor(value.
value<
QColor>());
4570 rendererConfig()->setIconBarColor(value.
value<
QColor>());
4572 rendererConfig()->setFoldingColor(value.
value<
QColor>());
4574 rendererConfig()->setLineNumberColor(value.
value<
QColor>());
4575 }
else if (key ==
QLatin1String(
"current-line-number-color")) {
4576 rendererConfig()->setCurrentLineNumberColor(value.
value<
QColor>());
4583 config()->setDynWordWrap(value.
toBool());
4585 config()->setShowWordCount(value.
toBool());
4587 config()->setShowLineCount(value.
toBool());
4590 rendererConfig()->setFont(value.
value<
QFont>());
4592 rendererConfig()->setSchema(value.
toString());
4599void KTextEditor::ViewPrivate::userInvokedCompletion()
4601 completionWidget()->userInvokedCompletion();
4604KateViewBar *KTextEditor::ViewPrivate::bottomViewBar()
const
4606 return m_bottomViewBar;
4609KateGotoBar *KTextEditor::ViewPrivate::gotoBar()
4612 m_gotoBar =
new KateGotoBar(
this);
4613 bottomViewBar()->addBarWidget(m_gotoBar);
4619KateDictionaryBar *KTextEditor::ViewPrivate::dictionaryBar()
4621 if (!m_dictionaryBar) {
4622 m_dictionaryBar =
new KateDictionaryBar(
this);
4623 bottomViewBar()->addBarWidget(m_dictionaryBar);
4626 return m_dictionaryBar;
4632 m_annotationModel = model;
4633 m_viewInternal->m_leftBorder->annotationModelChanged(oldmodel, m_annotationModel);
4638 return m_annotationModel;
4641void KTextEditor::ViewPrivate::setAnnotationBorderVisible(
bool visible)
4643 m_viewInternal->m_leftBorder->setAnnotationBorderOn(visible);
4646bool KTextEditor::ViewPrivate::isAnnotationBorderVisible()
const
4648 return m_viewInternal->m_leftBorder->annotationBorderOn();
4653 return m_viewInternal->m_leftBorder->annotationItemDelegate();
4658 m_viewInternal->m_leftBorder->setAnnotationItemDelegate(delegate);
4661bool KTextEditor::ViewPrivate::uniformAnnotationItemSizes()
const
4663 return m_viewInternal->m_leftBorder->uniformAnnotationItemSizes();
4666void KTextEditor::ViewPrivate::setAnnotationUniformItemSizes(
bool enable)
4668 m_viewInternal->m_leftBorder->setAnnotationUniformItemSizes(enable);
4674 if (!m_viewInternal->endPos().isValid()) {
4675 m_viewInternal->updateView();
4677 return KTextEditor::Range(m_viewInternal->toRealCursor(m_viewInternal->startPos()), m_viewInternal->toRealCursor(m_viewInternal->endPos()));
4680bool KTextEditor::ViewPrivate::event(
QEvent *e)
4682 switch (e->
type()) {
4691void KTextEditor::ViewPrivate::toggleOnTheFlySpellCheck(
bool b)
4693 doc()->onTheFlySpellCheckingEnabled(b);
4696void KTextEditor::ViewPrivate::reflectOnTheFlySpellCheckStatus(
bool enabled)
4698 m_spellingMenu->setVisible(enabled);
4699 m_toggleOnTheFlySpellCheck->setChecked(enabled);
4702KateSpellingMenu *KTextEditor::ViewPrivate::spellingMenu()
4704 return m_spellingMenu;
4707void KTextEditor::ViewPrivate::notifyAboutRangeChange(
KTextEditor::LineRange lineRange,
bool needsRepaint)
4709#ifdef VIEW_RANGE_DEBUG
4711 qCDebug(LOG_KTE) <<
"trigger attribute changed in line range " << lineRange <<
"needsRepaint" << needsRepaint;
4715 if (needsRepaint && lineRange.
isValid()) {
4716 if (m_lineToUpdateRange.isValid()) {
4717 m_lineToUpdateRange.expandToRange(lineRange);
4719 m_lineToUpdateRange = lineRange;
4724 if (!m_delayedUpdateTimer.isActive()) {
4725 m_delayedUpdateTimer.
start();
4729void KTextEditor::ViewPrivate::slotDelayedUpdateOfView()
4731#ifdef VIEW_RANGE_DEBUG
4733 qCDebug(LOG_KTE) <<
"delayed attribute changed in line range" << m_lineToUpdateRange;
4740 if (m_lineToUpdateRange.isValid()) {
4741 tagLines(m_lineToUpdateRange,
true);
4764 if (doc()->buffer().rangePointerValid(range)) {
4765 validRanges.
insert(range);
4770 if (currentCursor.
isValid() && currentCursor.
line() < doc()->buffer().lines()) {
4777 auto attribute = range->attribute();
4778 if ((!attribute || !attribute->dynamicAttribute(activationType)) && !range->feedback()) {
4784 : (currentCursor <= range->toRange().
start())) {
4789 : (range->toRange().
end() < currentCursor)) {
4794 auto it = validRanges.
find(range);
4795 if (it != validRanges.
end()) {
4797 newRangesIn.
insert(range);
4798 validRanges.
erase(it);
4803 newRangesIn.
insert(range);
4805 if (attribute && attribute->dynamicAttribute(activationType)) {
4806 notifyAboutRangeChange(range->
toLineRange(),
true);
4810 if (range->feedback()) {
4812 range->feedback()->mouseEnteredRange(range,
this);
4814 range->feedback()->caretEnteredRange(range,
this);
4815 Q_EMIT caretChangedRange(
this);
4819#ifdef VIEW_RANGE_DEBUG
4821 qCDebug(LOG_KTE) <<
"activated new range" << range <<
"by" << activationType;
4829 if (range->toRange().
isValid() && range->attribute() && range->attribute()->dynamicAttribute(activationType)) {
4830 notifyAboutRangeChange(range->
toLineRange(),
true);
4834 if (range->feedback()) {
4836 range->feedback()->mouseExitedRange(range,
this);
4838 range->feedback()->caretExitedRange(range,
this);
4839 Q_EMIT caretChangedRange(
this);
4845 oldSet = newRangesIn;
4851 auto messageWidget = m_messageWidgets[message->
position()];
4852 if (!messageWidget) {
4855 m_messageWidgets[message->
position()] = messageWidget;
4856 m_notificationLayout->addWidget(messageWidget, message->
position());
4860 messageWidget->postMessage(message, std::move(actions));
4868void KTextEditor::ViewPrivate::saveFoldingState()
4870 m_savedFoldingState = m_textFolding.exportFoldingRanges();
4873void KTextEditor::ViewPrivate::clearFoldingState()
4875 m_savedFoldingState = {};
4878void KTextEditor::ViewPrivate::applyFoldingState()
4880 m_textFolding.importFoldingRanges(m_savedFoldingState);
4884void KTextEditor::ViewPrivate::exportHtmlToFile(
const QString &file)
4886 KateExporter(
this).exportToFile(file);
4889void KTextEditor::ViewPrivate::exportHtmlToClipboard()
4891 KateExporter(
this).exportToClipboard();
4894void KTextEditor::ViewPrivate::exportHtmlToFile()
4898 KateExporter(
this).exportToFile(file);
4902void KTextEditor::ViewPrivate::clearHighlights()
4904 m_rangesForHighlights.clear();
4905 m_currentTextForHighlights.clear();
4908void KTextEditor::ViewPrivate::selectionChangedForHighlights()
4912 if (selection() && selectionRange().onSingleLine()) {
4913 text = selectionText();
4914 if (text == m_currentTextForHighlights) {
4921 m_rangesForHighlights.clear();
4929 m_currentTextForHighlights = text;
4933void KTextEditor::ViewPrivate::createHighlights()
4936 if (m_currentTextForHighlights.isEmpty()) {
4941 m_rangesForHighlights.clear();
4947 QColor fgColor = defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal)->foreground().color();
4948 QColor bgColor = rendererConfig()->searchHighlightColor();
4949 attr->setForeground(fgColor);
4950 attr->setBackground(bgColor);
4972 if (matches.
first().isValid()) {
4973 if (matches.
first() != selectionRange()) {
4974 std::unique_ptr<KTextEditor::MovingRange> mr(doc()->newMovingRange(matches.
first()));
4975 mr->setZDepth(-90000.0);
4976 mr->setAttribute(attr);
4978 mr->setAttributeOnlyForViews(
true);
4979 m_rangesForHighlights.push_back(std::move(mr));
4983 }
while (matches.
first().isValid());
4986KateAbstractInputMode *KTextEditor::ViewPrivate::currentInputMode()
const
4988 return m_viewInternal->m_currentInputMode;
4991void KTextEditor::ViewPrivate::toggleInputMode()
4993 if (
QAction *a = qobject_cast<QAction *>(sender())) {
4998void KTextEditor::ViewPrivate::cycleInputMode()
5000 InputMode current = currentInputMode()->viewInputMode();
5006bool KTextEditor::ViewPrivate::print()
5008 return KatePrinter::print(
this);
5011void KTextEditor::ViewPrivate::printPreview()
5013 KatePrinter::printPreview(
this);
5021 if (std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider) == m_inlineNoteProviders.cend()) {
5022 m_inlineNoteProviders.push_back(provider);
5033 auto it = std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider);
5034 if (it != m_inlineNoteProviders.cend()) {
5035 m_inlineNoteProviders.erase(it);
5048 for (
int column : columns) {
5049 const bool underMouse = Cursor(line, column) == m_viewInternal->m_activeInlineNote.m_position;
5051 {provider,
this, {line, column}, index, underMouse, m_viewInternal->renderer()->currentFont(), m_viewInternal->renderer()->lineHeight()};
5052 allInlineNotes.
append(note);
5056 return allInlineNotes;
5061 return m_viewInternal->inlineNoteRect(note);
5064void KTextEditor::ViewPrivate::inlineNotesReset()
5066 m_viewInternal->m_activeInlineNote = {};
5070void KTextEditor::ViewPrivate::inlineNotesLineChanged(
int line)
5072 if (line == m_viewInternal->m_activeInlineNote.m_position.line()) {
5073 m_viewInternal->m_activeInlineNote = {};
5075 tagLines({line, line},
true);
5082 KateRendererConfig *renderConfig =
const_cast<KTextEditor::ViewPrivate *
>(
this)->rendererConfig();
5088 style->setBackground(
QBrush(renderConfig->backgroundColor()));
5097 if (line < 0 || line >= doc()->lines()) {
5103 for (qsizetype i = 0; i < intAttrs.size(); ++i) {
5104 if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0) {
5105 attribs <<
KTextEditor::AttributeBlock(intAttrs.at(i).offset, intAttrs.at(i).length, renderer()->attribute(intAttrs.at(i).attributeValue));
5112void KTextEditor::ViewPrivate::copyFileLocation()
const
5118#include "moc_kateview.cpp"
Q_INVOKABLE QAction * action(const QString &name) const
void addAssociatedWidget(QWidget *widget)
QAction * addAction(const QString &name, const QObject *receiver=nullptr, const char *member=nullptr)
static void setDefaultShortcut(QAction *action, const QKeySequence &shortcut)
static Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList< QKeySequence > &shortcuts)
QList< QAction * > actions() const
bool hasKey(const char *key) const
void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags=Normal)
void deleteGroup(const QString &group, WriteConfigFlags flags=Normal)
QString readEntry(const char *key, const char *aDefault=nullptr) const
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
void canceled(const QString &errMsg)
void indexTriggered(int index)
A delegate for rendering line annotation information and handling events.
An model for providing line annotation information.
Attributes of a part of a line.
A class which provides customized text decorations.
ActivationType
Several automatic activation mechanisms exist for associated attributes.
@ ActivateMouseIn
Activate attribute on mouse in.
@ ActivateCaretIn
Activate attribute on caret in.
An item model for providing code completion, and meta information for enhanced presentation.
The Cursor represents a position in a Document.
constexpr int column() const noexcept
Retrieve the column on which this cursor is situated.
void setColumn(int column) noexcept
Set the cursor column to column.
void setPosition(Cursor position) noexcept
Set the current cursor position to position.
constexpr bool isValid() const noexcept
Returns whether the current position of this cursor is a valid position (line + column must both be >...
static constexpr Cursor start() noexcept
Returns a cursor representing the start of any document - i.e., line 0, column 0.
constexpr int line() const noexcept
Retrieve the line on which this cursor is situated.
static constexpr Cursor invalid() noexcept
Returns an invalid cursor.
Backend of KTextEditor::Document related public KTextEditor interfaces.
bool documentReload() override
Reloads the current document from disk if possible.
bool postMessage(KTextEditor::Message *message) override
Post message to the Document and its Views.
void joinLines(uint first, uint last)
Unwrap a range of lines.
QString text(KTextEditor::Range range, bool blockwise=false) const override
Get the document content within the given range.
void transform(KTextEditor::ViewPrivate *view, KTextEditor::Cursor, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
QString line(int line) const override
Get a single text line.
int lastLine() const
gets the last line number (lines() - 1)
KateBuffer & buffer()
Get access to buffer of this document.
int lines() const override
Get the count of lines of the document.
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor)
Returns the next or previous position cursor in this document from the stack depending on the argumen...
KateDocumentConfig * config()
Configuration.
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=nullptr, bool notify=true)
Wrap line.
void removeAllTrailingSpaces()
This function doesn't check for config and is available for use all the time via an action.
Kate::TextLine kateTextLine(int i)
Same as plainKateTextLine(), except that it is made sure the line is highlighted.
bool editEnd()
End a editor operation.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
int lineLength(int line) const override
Get the length of a given line in characters.
KTextEditor::Range wordRangeAt(KTextEditor::Cursor cursor) const override
Get the text range for the word located under the text position cursor.
void removeView(KTextEditor::View *)
removes the view from the list of views.
bool wrapParagraph(int first, int last)
Wrap lines touched by the selection with respect of existing paragraphs.
Editing transaction support.
A KParts derived class representing a text document.
void reloaded(KTextEditor::Document *document)
Emitted after the current document was reloaded.
Range documentRange() const
A Range which encompasses the whole document.
void highlightingModeChanged(KTextEditor::Document *document)
Warn anyone listening that the current document's highlighting mode has changed.
void aboutToReload(KTextEditor::Document *document)
Warn anyone listening that the current document is about to reload.
void copyToClipboard(const QString &text, const QString &fileName)
Copy text to clipboard an remember it in the history.
void deregisterView(KTextEditor::ViewPrivate *view)
unregister view at the factory
QTextToSpeech * speechEngine(KTextEditor::ViewPrivate *view)
text to speech engine to be use by the view actions, constructed on demand.
void configDialog(QWidget *parent) override
Configuration management.
void registerView(KTextEditor::ViewPrivate *view)
register view at the factory this allows us to loop over all views for example on config changes
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
A source of inline notes for a document.
void inlineNotesReset()
The provider should emit the signal inlineNotesReset() when almost all inline notes changed.
void inlineNotesChanged(int line)
The provider should emit the signal inlineNotesChanged() whenever one or more InlineNotes on the line...
virtual QList< int > inlineNotes(int line) const =0
Get list of inline notes for given line.
An object representing lines from a start line to an end line.
constexpr int start() const noexcept
Get the start line of this line range.
static constexpr LineRange invalid() noexcept
Returns an invalid line range.
constexpr bool isValid() const noexcept
Validity check.
constexpr int end() const noexcept
Get the end line of this line range.
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
This class holds a Message to display in Views.
@ BelowView
show message below view.
@ AboveView
show message above view.
@ TopInView
show message as view overlay in the top right corner.
@ BottomInView
show message as view overlay in the bottom right corner.
void setAutoHide(int delay=0)
Set the auto hide time to delay milliseconds.
void setAutoHideMode(KTextEditor::Message::AutoHideMode mode)
Sets the auto hide mode to mode.
MessagePosition position() const
Returns the message position of this message.
@ Information
information message type
@ Immediate
auto-hide is triggered as soon as the message is shown
void setPosition(MessagePosition position)
Sets the position of the message to position.
@ StayOnInsert
stay on insert
@ ExpandRight
Expand to encapsulate new characters to the right of the range.
@ ExpandLeft
Expand to encapsulate new characters to the left of the range.
An object representing a section of text, from one Cursor to another.
constexpr LineRange toLineRange() const noexcept
Convert this Range to a LineRange.
constexpr Cursor end() const noexcept
Get the end position of this range.
constexpr Cursor start() const noexcept
Get the start position of this range.
void setEnd(Cursor end) noexcept
Set the end cursor to end.
constexpr bool isEmpty() const noexcept
Returns true if this range contains no characters, ie.
void setRange(Range range) noexcept
Set the start and end cursors to range.start() and range.end() respectively.
constexpr bool onSingleLine() const noexcept
Check whether this range is wholly contained within one line, ie.
static constexpr Range invalid() noexcept
Returns an invalid range.
constexpr bool isValid() const noexcept
Validity check.
constexpr bool containsLine(int line) const noexcept
Returns true if this range wholly encompasses line.
constexpr bool contains(Range range) const noexcept
Check whether the this range wholly encompasses range.
void setStart(Cursor start) noexcept
Set the start cursor to start.
Class to provide text hints for a View.
A text widget with KXMLGUIClient that represents a Document.
ViewMode
Possible view modes These correspond to various modes the text editor might be in.
InputMode
Possible input modes.
@ NormalInputMode
Normal Mode.
void cursorPositionChanged(KTextEditor::View *view, KTextEditor::Cursor newPosition)
This signal is emitted whenever the view's cursor position changed.
void selectionChanged(KTextEditor::View *view)
This signal is emitted whenever the view's selection changes.
KXMLGUIClient * parentClient() const
KXMLGUIFactory * factory() const
virtual void setComponentName(const QString &componentName, const QString &componentDisplayName)
void removeClient(KXMLGUIClient *client)
KTextEditor::Range computeFoldingRangeForStartLine(int startLine)
For a given line, compute the folding range that starts there to be used to fold e....
Internal data container for KTextEditor::InlineNote interface.
Class to layout KTextEditor::Messages in KateView.
Handles all of the work of rendering the text (used for the views and printing)
Inserts a template and offers advanced snippet features, like navigation and mirroring.
This action provides a list of available indenters and gets plugged into the KTextEditor::ViewPrivate...
QList< TextRange * > rangesForLine(int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
Return the ranges which affect the given line.
Class representing a 'clever' text cursor.
@ Folded
Range is folded away.
Class representing a single text line.
const QString & text() const
Accessor to the text contained in this line.
const QList< Attribute > & attributesList() const
Accessor to attributes.
QString string(int column, int length) const
Returns the substring with length beginning at the given column.
int length() const
Returns the line's length.
QChar at(int column) const
Returns the character at the given column.
int firstChar() const
Returns the position of the first non-whitespace character.
Q_SCRIPTABLE Q_NOREPLY void start()
Q_SCRIPTABLE bool focusOut(int ms=-1)
Q_SCRIPTABLE bool focusIn(int ms=-1)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
void update(Part *part, const QByteArray &data, qint64 dataSize)
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT CopyJob * copy(const QList< QUrl > &src, const QUrl &dest, JobFlags flags=DefaultFlags)
KIOWIDGETS_EXPORT PasteJob * paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags=DefaultFlags)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
const QList< QKeySequence > & beginningOfLine()
const QList< QKeySequence > & begin()
const QList< QKeySequence > & reload()
const QList< QKeySequence > & zoomIn()
const QList< QKeySequence > & zoomOut()
const QList< QKeySequence > & next()
const QList< QKeySequence > & deleteWordBack()
const QList< QKeySequence > & end()
const QList< QKeySequence > & backwardWord()
const QList< QKeySequence > & endOfLine()
const QList< QKeySequence > & forwardWord()
const QList< QKeySequence > & shortcut(StandardShortcut id)
const QList< QKeySequence > & deleteWordForward()
const QList< QKeySequence > & prior()
const QList< QKeySequence > & pasteSelection()
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
@ Default
Default settings.
@ Regex
Treats the pattern as a regular expression.
QVariant data() const const
void setIcon(const QIcon &icon)
void setText(const QString &text)
void triggered(bool checked)
void setWhatsThis(const QString &what)
bool isLetterOrNumber(char32_t ucs4)
bool isSpace(char32_t ucs4)
void setText(const QString &text, Mode mode)
bool supportsSelection() const const
QString text(Mode mode) const const
QColor fromRgba(QRgb rgba)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, Options options)
virtual void addItem(QLayoutItem *item) override
void setColumnStretch(int column, int stretch)
void setRowStretch(int row, int stretch)
virtual void setSpacing(int spacing) override
QIcon fromTheme(const QString &name)
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
void setContentsMargins(const QMargins &margins)
void append(QList< T > &&value)
const T & constFirst() const const
bool isEmpty() const const
void push_back(parameter_type value)
void reserve(qsizetype size)
qsizetype size() const const
bool disconnect(const QMetaObject::Connection &connection)
UseUnicodePropertiesOption
QString escape(QStringView str)
iterator erase(const_iterator pos)
iterator find(const T &value)
iterator insert(const T &value)
const QChar at(qsizetype position) const const
bool isEmpty() const const
bool isRightToLeft() const const
qsizetype length() const const
QString number(double n, char format, int precision)
QString & prepend(QChar ch)
void reserve(qsizetype size)
SH_ScrollView_FrameOnlyAroundContents
void initFrom(const QWidget *widget)
WidgetWithChildrenShortcut
QTextStream & bom(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool canConvert() const const
bool toBool() const const
int toInt(bool *ok) const const
QString toString() const const
int userType() const const
iterator erase(const_iterator begin, const_iterator end)
qsizetype size() const const