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) {
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->undoManager(), &KateUndoManager::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_convertTabsSpaces"));
526 doc()->
config()->setReplaceTabsDyn(
true);
527 doc()->indent(doc()->documentRange(), 0);
530 a = ac->
addAction(QStringLiteral(
"tools_convertSpacesTabs"));
533 auto config = doc()->
config();
534 if (config->replaceTabsDyn()) {
535 config->configStart();
536 config->setReplaceTabsDyn(
false);
537 config->setTabWidth(config->indentationWidth());
540 config->setTabWidth(config->indentationWidth());
542 doc()->indent(doc()->documentRange(), 0);
545 a = ac->
addAction(QStringLiteral(
"tools_formatIndent"));
547 a->setWhatsThis(
i18n(
"Use this to auto indent the current line or block of text to its proper indent level."));
550 a = ac->
addAction(QStringLiteral(
"tools_alignOn"));
553 i18n(
"This command aligns lines in the selected block or whole document on the column given by a regular expression "
554 "that you will be prompted for.<br /><br />"
555 "If you give an empty pattern it will align on the first non-blank character by default.<br />"
556 "If the pattern has a capture it will indent on the captured match.<br /><br />"
557 "<i>Examples</i>:<br />"
558 "With '-' it will insert spaces before the first '-' of each lines to align them all on the same column.<br />"
559 "With ':\\s+(.)' it will insert spaces before the first non-blank character that occurs after a colon to align "
560 "them all on the same column."));
563 a = ac->
addAction(QStringLiteral(
"tools_comment"));
567 i18n(
"This command comments out the current line or a selected block of text.<br /><br />"
568 "The characters for single/multiple line comments are defined within the language's highlighting."));
571 a = ac->
addAction(QStringLiteral(
"Previous Editing Line"));
572 a->
setText(
i18n(
"Go to Previous Editing Location"));
577 a = ac->
addAction(QStringLiteral(
"Next Editing Line"));
583 a = ac->
addAction(QStringLiteral(
"tools_uncomment"));
587 i18n(
"This command removes comments from the current line or a selected block of text.<br /><br />"
588 "The characters for single/multiple line comments are defined within the language's highlighting."));
591 a = ac->
addAction(QStringLiteral(
"tools_toggle_comment"));
597 a->setWhatsThis(
i18n(
"Lock/unlock the document for writing"));
598 a->setChecked(!doc()->isReadWrite());
600 ac->
addAction(QStringLiteral(
"tools_toggle_write_lock"), a);
603 a->setWhatsThis(
i18n(
"Force RTL Text Direction"));
605 m_forceRTL = checked;
609 ac->
addAction(QStringLiteral(
"force_rtl_direction"), a);
611 a = ac->
addAction(QStringLiteral(
"tools_uppercase"));
613 a->setText(
i18n(
"Uppercase"));
616 i18n(
"Convert the selection to uppercase, or the character to the "
617 "right of the cursor if no text is selected."));
620 a = ac->
addAction(QStringLiteral(
"tools_lowercase"));
622 a->setText(
i18n(
"Lowercase"));
625 i18n(
"Convert the selection to lowercase, or the character to the "
626 "right of the cursor if no text is selected."));
629 a = ac->
addAction(QStringLiteral(
"tools_capitalize"));
631 a->setText(
i18n(
"Capitalize"));
634 i18n(
"Capitalize the selection, or the word under the "
635 "cursor if no text is selected."));
638 a = ac->
addAction(QStringLiteral(
"tools_join_lines"));
643 a = ac->
addAction(QStringLiteral(
"tools_invoke_code_completion"));
645 a->setWhatsThis(
i18n(
"Manually invoke command completion, usually by using a shortcut bound to this action."));
649 a = ac->
addAction(QStringLiteral(
"remove_trailing_spaces"));
655 for (
auto *action : {m_cut, m_paste, m_clipboardHistory, m_swapWithClipboard}) {
656 action->setEnabled(
false);
659 if (m_pasteSelection) {
660 m_pasteSelection->setEnabled(
false);
663 m_editUndo =
nullptr;
664 m_editRedo =
nullptr;
673 a = ac->
addAction(QStringLiteral(
"file_reload"));
675 a->setText(
i18n(
"Reloa&d"));
677 a->setWhatsThis(
i18n(
"Reload the current document from disk."));
681 a->
setWhatsThis(
i18n(
"Save the current document to disk, with a name of your choice."));
683 a =
new KateViewEncodingAction(m_doc,
this,
i18nc(
"@action",
"Save As with Encodin&g…"),
this,
true );
685 ac->
addAction(QStringLiteral(
"file_save_as_with_encoding"), a);
687 a = ac->
addAction(QStringLiteral(
"file_save_copy_as"));
689 a->setText(
i18nc(
"@action",
"Save Cop&y As…"));
690 a->setWhatsThis(
i18n(
"Save a copy of the current document to disk."));
694 a->
setWhatsThis(
i18n(
"This command opens a dialog and lets you choose a line that you want the cursor to move to."));
696 a = ac->
addAction(QStringLiteral(
"modified_line_up"));
698 a->setText(
i18n(
"Go to Previous Modified Line"));
699 a->setWhatsThis(
i18n(
"Move upwards to the previous modified line."));
702 a = ac->
addAction(QStringLiteral(
"modified_line_down"));
704 a->setText(
i18n(
"Go to Next Modified Line"));
705 a->setWhatsThis(
i18n(
"Move downwards to the next modified line."));
708 a = ac->
addAction(QStringLiteral(
"set_confdlg"));
711 a->setWhatsThis(
i18n(
"Configure various aspects of this editor."));
714 m_modeAction =
new KateModeMenu(
i18n(
"&Mode"),
this);
715 ac->
addAction(QStringLiteral(
"tools_mode"), m_modeAction);
717 "Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
718 m_modeAction->updateMenu(m_doc);
720 KateHighlightingMenu *menu =
new KateHighlightingMenu(
i18n(
"&Highlighting"),
this);
721 ac->
addAction(QStringLiteral(
"tools_highlighting"), menu);
722 menu->
setWhatsThis(
i18n(
"Here you can choose how the current document should be highlighted."));
723 menu->updateMenu(m_doc);
725 KateViewSchemaAction *schemaMenu =
new KateViewSchemaAction(
i18n(
"&Editor Color Theme"),
this);
727 ac->
addAction(QStringLiteral(
"view_schemas"), schemaMenu);
728 schemaMenu->updateMenu(
this);
732 ac->
addAction(QStringLiteral(
"tools_indentation"), indentMenu);
741 a->
setWhatsThis(
i18n(
"If you have selected something within the current document, this will no longer be selected."));
743 a = ac->
addAction(QStringLiteral(
"view_inc_font_sizes"));
745 a->setText(
i18n(
"Enlarge Font"));
747 a->setWhatsThis(
i18n(
"This increases the display font size."));
749 m_viewInternal->slotIncFontSizes();
752 a = ac->
addAction(QStringLiteral(
"view_dec_font_sizes"));
754 a->setText(
i18n(
"Shrink Font"));
756 a->setWhatsThis(
i18n(
"This decreases the display font size."));
758 m_viewInternal->slotDecFontSizes();
761 a = ac->
addAction(QStringLiteral(
"view_reset_font_sizes"));
763 a->setText(
i18n(
"Reset Font Size"));
765 a->setWhatsThis(
i18n(
"This resets the display font size."));
768 a = m_toggleBlockSelection =
new KToggleAction(
i18n(
"Bl&ock Selection Mode"),
this);
769 ac->
addAction(QStringLiteral(
"set_verticalSelect"), a);
771 a->setWhatsThis(
i18n(
"This command allows switching between the normal (line based) selection mode and the block selection mode."));
774 a = ac->
addAction(QStringLiteral(
"switch_next_input_mode"));
777 a->setWhatsThis(
i18n(
"Switch to the next input mode."));
781 ac->
addAction(QStringLiteral(
"set_insert"), a);
783 a->setWhatsThis(
i18n(
"Choose whether you want the text you type to be inserted or to overwrite existing text."));
787 a = m_toggleShowSpace = toggleAction =
new KToggleAction(
i18n(
"Show Whitespace"),
this);
788 ac->
addAction(QStringLiteral(
"view_show_whitespaces"), a);
790 i18n(
"If this option is checked, whitespaces in this document will be visible.<br /><br />"
791 "This is only a view option, meaning the document will not be changed."));
794 a = m_toggleDynWrap = toggleAction =
new KToggleAction(
i18n(
"&Dynamic Word Wrap"),
this);
796 ac->
addAction(QStringLiteral(
"view_dynamic_word_wrap"), a);
798 i18n(
"If this option is checked, the text lines will be wrapped at the view border on the screen.<br /><br />"
799 "This is only a view option, meaning the document will not be changed."));
802 a = m_setDynWrapIndicators =
new KSelectAction(
i18n(
"Dynamic Word Wrap Indicators"),
this);
803 ac->
addAction(QStringLiteral(
"dynamic_word_wrap_indicators"), a);
804 a->
setWhatsThis(
i18n(
"Choose when the Dynamic Word Wrap Indicators should be displayed"));
807 m_setDynWrapIndicators->setItems(list2);
808 m_setDynWrapIndicators->setEnabled(m_toggleDynWrap->isChecked());
811 ac->
addAction(QStringLiteral(
"view_static_word_wrap"), a);
812 a->
setWhatsThis(
i18n(
"If this option is checked, the text lines will be wrapped at the column defined in the editing properties."));
815 m_doc->setWordWrap(!m_doc->wordWrap());
819 a = toggleAction = m_toggleWWMarker =
new KToggleAction(
i18n(
"Show Static &Word Wrap Marker"),
this);
820 ac->
addAction(QStringLiteral(
"view_word_wrap_marker"), a);
822 i18n(
"Show/hide the Word Wrap Marker, a vertical line drawn at the word "
823 "wrap column as defined in the editing properties"));
826 a = toggleAction = m_toggleFoldingMarkers =
new KToggleAction(
i18n(
"Show Folding &Markers"),
this);
827 ac->
addAction(QStringLiteral(
"view_folding_markers"), a);
828 a->
setWhatsThis(
i18n(
"You can choose if the codefolding marks should be shown, if codefolding is possible."));
831 a = m_toggleIconBar = toggleAction =
new KToggleAction(
i18n(
"Show &Icon Border"),
this);
832 ac->
addAction(QStringLiteral(
"view_border"), a);
833 a->
setWhatsThis(
i18n(
"Show/hide the icon border.<br /><br />The icon border shows bookmark symbols, for instance."));
836 a = toggleAction = m_toggleLineNumbers =
new KToggleAction(
i18n(
"Show &Line Numbers"),
this);
837 ac->
addAction(QStringLiteral(
"view_line_numbers"), a);
838 a->
setWhatsThis(
i18n(
"Show/hide the line numbers on the left hand side of the view."));
841 a = m_toggleScrollBarMarks = toggleAction =
new KToggleAction(
i18n(
"Show Scroll&bar Marks"),
this);
842 ac->
addAction(QStringLiteral(
"view_scrollbar_marks"), a);
843 a->
setWhatsThis(
i18n(
"Show/hide the marks on the vertical scrollbar.<br /><br />The marks show bookmarks, for instance."));
846 a = m_toggleScrollBarMiniMap = toggleAction =
new KToggleAction(
i18n(
"Show Scrollbar Mini-Map"),
this);
847 ac->
addAction(QStringLiteral(
"view_scrollbar_minimap"), a);
848 a->
setWhatsThis(
i18n(
"Show/hide the mini-map on the vertical scrollbar.<br /><br />The mini-map shows an overview of the whole document."));
851 a = m_doc->autoReloadToggleAction();
852 ac->
addAction(QStringLiteral(
"view_auto_reload"), a);
860 a = m_toggleNPSpaces =
new KToggleAction(
i18n(
"Show Non-Printable Spaces"),
this);
861 ac->
addAction(QStringLiteral(
"view_non_printable_spaces"), a);
862 a->
setWhatsThis(
i18n(
"Show/hide bounding box around non-printable spaces"));
865 a = m_switchCmdLine = ac->
addAction(QStringLiteral(
"switch_to_cmd_line"));
868 a->setWhatsThis(
i18n(
"Show/hide the command line on the bottom of the view."));
873 ac->
addAction(QStringLiteral(
"view_input_modes"), am);
874 auto switchInputModeAction = ac->
action(QStringLiteral(
"switch_next_input_mode"));
877 for (
const auto &mode : m_viewInternal->m_inputModes) {
878 a =
new QAction(mode->viewInputModeHuman(), m_inputModeActions);
880 a->setWhatsThis(
i18n(
"Activate/deactivate %1", mode->viewInputModeHuman()));
881 const InputMode im = mode->viewInputMode();
882 a->setData(
static_cast<int>(im));
883 a->setCheckable(
true);
884 if (im == m_config->inputMode()) {
891 ac->
addAction(QStringLiteral(
"set_eol"), a);
892 a->
setWhatsThis(
i18n(
"Choose which line endings should be used, when you save the document"));
894 i18nc(
"@item:inmenu End of Line",
"&Windows/DOS"),
895 i18nc(
"@item:inmenu End of Line",
"&Macintosh")};
896 m_setEndOfLine->setItems(list);
897 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
901 m_addBom->setChecked(doc()->config()->
bom());
902 ac->
addAction(QStringLiteral(
"add_bom"), a);
903 a->
setWhatsThis(
i18n(
"Enable/disable adding of byte order marks for UTF-8/UTF-16 encoded files while saving"));
907 m_encodingAction =
new KateViewEncodingAction(m_doc,
this,
i18n(
"E&ncoding"),
this);
908 ac->
addAction(QStringLiteral(
"set_encoding"), m_encodingAction);
911 a->
setWhatsThis(
i18n(
"Look up the first occurrence of a piece of text or regular expression."));
914 a = ac->
addAction(QStringLiteral(
"edit_find_selected"));
917 a->setWhatsThis(
i18n(
"Finds next occurrence of selected text."));
920 a = ac->
addAction(QStringLiteral(
"edit_find_selected_backwards"));
923 a->setWhatsThis(
i18n(
"Finds previous occurrence of selected text."));
926 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_next_occurrence"));
927 a->
setText(
i18n(
"Find and Select Next Occurrence"));
929 a->setWhatsThis(
i18n(
"Finds next occurrence of the word under cursor and add it to selection."));
932 a = ac->
addAction(QStringLiteral(
"edit_skip_multicursor_current_occurrence"));
933 a->
setText(
i18n(
"Mark Currently Selected Occurrence as Skipped"));
935 a->setWhatsThis(
i18n(
"Marks the currently selected word as skipped."));
938 a = ac->
addAction(QStringLiteral(
"edit_find_multicursor_all_occurrences"));
939 a->
setText(
i18n(
"Find and Select All Occurrences"));
941 a->setWhatsThis(
i18n(
"Finds all occurrences of the word under cursor and selects them."));
949 a->
setWhatsThis(
i18n(
"Look up the previous occurrence of the search phrase."));
953 a->
setWhatsThis(
i18n(
"Look up a piece of text or regular expression and replace the result with some given text."));
955 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_from_sel"));
958 a->setWhatsThis(
i18n(
"Creates a cursor at the end of every line in selection."));
961 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_down"));
964 a->setWhatsThis(
i18n(
"Adds a caret in the line below the current caret."));
967 a = ac->
addAction(QStringLiteral(
"edit_create_multi_cursor_up"));
970 a->setWhatsThis(
i18n(
"Adds a caret in the line above the current caret."));
973 a = ac->
addAction(QStringLiteral(
"edit_toggle_camel_case_cursor"));
974 a->
setText(
i18n(
"Toggle Camel Case Cursor Movement"));
975 a->setWhatsThis(
i18n(
"Toggle between normal word movement and camel case cursor movement."));
978 a = ac->
addAction(QStringLiteral(
"edit_remove_cursors_from_empty_lines"));
979 a->
setText(
i18n(
"Remove Cursors from Empty Lines"));
980 a->setWhatsThis(
i18n(
"Remove cursors from empty lines"));
983 m_spell->createActions(ac);
984 m_toggleOnTheFlySpellCheck =
new KToggleAction(
i18n(
"Automatic Spell Checking"),
this);
985 m_toggleOnTheFlySpellCheck->setWhatsThis(
i18n(
"Enable/disable automatic spell checking"));
987 ac->
addAction(QStringLiteral(
"tools_toggle_automatic_spell_checking"), m_toggleOnTheFlySpellCheck);
990 a = ac->
addAction(QStringLiteral(
"tools_change_dictionary"));
992 a->setWhatsThis(
i18n(
"Change the dictionary that is used for spell checking."));
995 a = ac->
addAction(QStringLiteral(
"tools_clear_dictionary_ranges"));
997 a->setEnabled(
false);
998 a->setWhatsThis(
i18n(
"Remove all the separate dictionary ranges that were set for spell checking."));
1002 m_copyHtmlAction = ac->
addAction(QStringLiteral(
"edit_copy_html"),
this, SLOT(exportHtmlToClipboard()));
1004 m_copyHtmlAction->setText(
i18n(
"Copy as &HTML"));
1005 m_copyHtmlAction->setWhatsThis(
i18n(
"Use this command to copy the currently selected text as HTML to the system clipboard."));
1007 a = ac->
addAction(QStringLiteral(
"file_export_html"),
this, SLOT(exportHtmlToFile()));
1009 a->setText(
i18nc(
"@action",
"E&xport as HTML…"));
1011 i18n(
"This command allows you to export the current document"
1012 " with all highlighting information into a HTML document."));
1014 m_spellingMenu->createActions(ac);
1016 m_bookmarks->createActions(ac);
1018 slotSelectionChanged();
1024 setupSpeechActions();
1028 const auto actions = ac->
actions();
1029 for (
QAction *action : actions) {
1036void KTextEditor::ViewPrivate::slotConfigDialog()
1042void KTextEditor::ViewPrivate::setupEditActions()
1053 m_editActions.push_back(a);
1055 a = ac->
addAction(QStringLiteral(
"select_char_left"));
1059 m_editActions.push_back(a);
1061 a = ac->
addAction(QStringLiteral(
"select_word_left"));
1065 m_editActions.push_back(a);
1067 a = ac->
addAction(QStringLiteral(
"word_right"));
1071 m_editActions.push_back(a);
1073 a = ac->
addAction(QStringLiteral(
"select_char_right"));
1077 m_editActions.push_back(a);
1079 a = ac->
addAction(QStringLiteral(
"select_word_right"));
1083 m_editActions.push_back(a);
1085 a = ac->
addAction(QStringLiteral(
"mark_selection"));
1087 a->
setWhatsThis(
i18n(
"Emulate the Emacs-like selection mode, where the beginning is marked and then the selection is continuously updated."));
1089 m_editActions.push_back(a);
1091 a = ac->
addAction(QStringLiteral(
"beginning_of_line"));
1095 m_editActions.push_back(a);
1097 a = ac->
addAction(QStringLiteral(
"beginning_of_document"));
1098 a->
setText(
i18n(
"Move to Beginning of Document"));
1101 m_editActions.push_back(a);
1103 a = ac->
addAction(QStringLiteral(
"select_beginning_of_line"));
1107 m_editActions.push_back(a);
1109 a = ac->
addAction(QStringLiteral(
"select_beginning_of_document"));
1110 a->
setText(
i18n(
"Select to Beginning of Document"));
1113 m_editActions.push_back(a);
1115 a = ac->
addAction(QStringLiteral(
"end_of_line"));
1119 m_editActions.push_back(a);
1121 a = ac->
addAction(QStringLiteral(
"end_of_document"));
1125 m_editActions.push_back(a);
1127 a = ac->
addAction(QStringLiteral(
"select_end_of_line"));
1131 m_editActions.push_back(a);
1133 a = ac->
addAction(QStringLiteral(
"select_end_of_document"));
1137 m_editActions.push_back(a);
1139 a = ac->
addAction(QStringLiteral(
"select_line_up"));
1143 m_editActions.push_back(a);
1145 a = ac->
addAction(QStringLiteral(
"scroll_line_up"));
1149 m_editActions.push_back(a);
1151 a = ac->
addAction(QStringLiteral(
"move_line_down"));
1155 m_editActions.push_back(a);
1157 a = ac->
addAction(QStringLiteral(
"move_line_up"));
1161 m_editActions.push_back(a);
1163 a = ac->
addAction(QStringLiteral(
"move_cursor_right"));
1167 m_editActions.push_back(a);
1169 a = ac->
addAction(QStringLiteral(
"move_cursor_left"));
1173 m_editActions.push_back(a);
1175 a = ac->
addAction(QStringLiteral(
"select_line_down"));
1179 m_editActions.push_back(a);
1181 a = ac->
addAction(QStringLiteral(
"scroll_line_down"));
1185 m_editActions.push_back(a);
1187 a = ac->
addAction(QStringLiteral(
"scroll_page_up"));
1191 m_editActions.push_back(a);
1193 a = ac->
addAction(QStringLiteral(
"select_page_up"));
1197 m_editActions.push_back(a);
1199 a = ac->
addAction(QStringLiteral(
"move_top_of_view"));
1203 m_editActions.push_back(a);
1205 a = ac->
addAction(QStringLiteral(
"select_top_of_view"));
1209 m_editActions.push_back(a);
1211 a = ac->
addAction(QStringLiteral(
"scroll_page_down"));
1215 m_editActions.push_back(a);
1217 a = ac->
addAction(QStringLiteral(
"select_page_down"));
1221 m_editActions.push_back(a);
1223 a = ac->
addAction(QStringLiteral(
"move_bottom_of_view"));
1227 m_editActions.push_back(a);
1229 a = ac->
addAction(QStringLiteral(
"select_bottom_of_view"));
1233 m_editActions.push_back(a);
1235 a = ac->
addAction(QStringLiteral(
"to_matching_bracket"));
1241 a = ac->
addAction(QStringLiteral(
"select_matching_bracket"));
1248 if (!doc()->readOnly()) {
1249 a = ac->
addAction(QStringLiteral(
"transpose_char"));
1252 m_editActions.push_back(a);
1254 a = ac->
addAction(QStringLiteral(
"transpose_word"));
1257 m_editActions.push_back(a);
1259 a = ac->
addAction(QStringLiteral(
"delete_line"));
1263 m_editActions.push_back(a);
1265 a = ac->
addAction(QStringLiteral(
"delete_word_left"));
1269 m_editActions.push_back(a);
1271 a = ac->
addAction(QStringLiteral(
"delete_word_right"));
1275 m_editActions.push_back(a);
1277 a = ac->
addAction(QStringLiteral(
"delete_next_character"));
1281 m_editActions.push_back(a);
1283 a = ac->
addAction(QStringLiteral(
"backspace"));
1289 m_editActions.push_back(a);
1291 a = ac->
addAction(QStringLiteral(
"insert_tabulator"));
1294 m_editActions.push_back(a);
1296 a = ac->
addAction(QStringLiteral(
"smart_newline"));
1298 a->
setWhatsThis(
i18n(
"Insert newline including leading characters of the current line which are not letters or numbers."));
1303 m_editActions.push_back(a);
1305 a = ac->
addAction(QStringLiteral(
"no_indent_newline"));
1306 a->
setText(
i18n(
"Insert a Non-Indented Newline"));
1307 a->
setWhatsThis(
i18n(
"Insert a new line without indentation, regardless of indentation settings."));
1312 m_editActions.push_back(a);
1314 a = ac->
addAction(QStringLiteral(
"newline_above"));
1315 a->
setText(
i18n(
"Insert a Newline Above Current Line"));
1316 a->
setWhatsThis(
i18n(
"Insert a new line above current line without modifying the current line."));
1321 m_editActions.push_back(a);
1323 a = ac->
addAction(QStringLiteral(
"newline_below"));
1324 a->
setText(
i18n(
"Insert a Newline Below Current Line"));
1325 a->
setWhatsThis(
i18n(
"Insert a new line below current line without modifying the current line."));
1330 m_editActions.push_back(a);
1332 a = ac->
addAction(QStringLiteral(
"tools_indent"));
1336 i18n(
"Use this to indent a selected block of text.<br /><br />"
1337 "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog."));
1341 a = ac->
addAction(QStringLiteral(
"tools_unindent"));
1356void KTextEditor::ViewPrivate::setupCodeFolding()
1361 a = ac->
addAction(QStringLiteral(
"folding_toplevel"));
1365 a = ac->
addAction(QStringLiteral(
"folding_expandtoplevel"));
1369 a = ac->
addAction(QStringLiteral(
"folding_toggle_current"));
1373 a = ac->
addAction(QStringLiteral(
"folding_toggle_in_current"));
1378void KTextEditor::ViewPrivate::setupSpeechActions()
1383 a->
setText(
i18n(
"Say current selection or document"));
1392 a = ac->
addAction(QStringLiteral(
"tools_speech_stop"));
1398 a = ac->
addAction(QStringLiteral(
"tools_speech_pause"));
1404 a = ac->
addAction(QStringLiteral(
"tools_speech_resume"));
1411void KTextEditor::ViewPrivate::slotFoldToplevelNodes()
1413 for (
int line = 0; line < doc()->
lines(); ++line) {
1414 if (textFolding().isLineVisible(line)) {
1420void KTextEditor::ViewPrivate::slotExpandToplevelNodes()
1422 const auto topLevelRanges(textFolding().foldingRangesForParentRange());
1423 for (
const auto &range : topLevelRanges) {
1424 textFolding().unfoldRange(range.first);
1428void KTextEditor::ViewPrivate::slotToggleFolding()
1430 int line = cursorPosition().line();
1431 bool actionDone =
false;
1432 while (!actionDone && (line > -1)) {
1433 actionDone = unfoldLine(line);
1435 actionDone = foldLine(line--).isValid();
1440void KTextEditor::ViewPrivate::slotToggleFoldingsInRange()
1442 int line = cursorPosition().line();
1443 while (!toggleFoldingsInRange(line) && (line > -1)) {
1451 if (!foldingRange.
isValid()) {
1452 return foldingRange;
1457 if (!m_doc->buffer().isFoldingStartingOnLine(line).second && !foldingRange.
onSingleLine()) {
1458 const int adjustedLine = foldingRange.
end().
line() - 1;
1466 auto folds = textFolding().foldingRangesStartingOnLine(line);
1467 for (
int i = 0; i < folds.size(); ++i) {
1469 if (fold == foldingRange) {
1470 return foldingRange;
1480 return foldingRange;
1483bool KTextEditor::ViewPrivate::unfoldLine(
int line)
1485 bool actionDone =
false;
1490 auto startingRanges = textFolding().foldingRangesStartingOnLine(line);
1491 for (
int i = 0; i < startingRanges.size() && !actionDone; ++i) {
1493 setCursorPosition(textFolding().foldingRange(startingRanges[i].first).
start());
1495 actionDone |= textFolding().unfoldRange(startingRanges[i].first);
1500 setCursorPosition(currentCursor);
1506bool KTextEditor::ViewPrivate::toggleFoldingOfLine(
int line)
1508 bool actionDone = unfoldLine(line);
1510 actionDone = foldLine(line).isValid();
1516bool KTextEditor::ViewPrivate::toggleFoldingsInRange(
int line)
1519 if (!foldingRange.
isValid()) {
1524 bool actionDone =
false;
1529 actionDone |= unfoldLine(line);
1533 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1534 actionDone |= unfoldLine(ln);
1539 setCursorPosition(currentCursor);
1545 for (
int ln = foldingRange.
start().
line() + 1; ln < foldingRange.
end().
line(); ++ln) {
1549 ln = qMax(ln, fr.
end().
line() - 1);
1558 actionDone |= foldLine(line).isValid();
1567 return currentInputMode()->viewMode();
1570QString KTextEditor::ViewPrivate::viewModeHuman()
const
1572 QString currentMode = currentInputMode()->viewModeHuman();
1575 if (!doc()->isReadWrite()) {
1576 currentMode =
i18n(
"(R/O) %1", currentMode);
1585 return currentInputMode()->viewInputMode();
1588QString KTextEditor::ViewPrivate::viewInputModeHuman()
const
1590 return currentInputMode()->viewInputModeHuman();
1595 if (currentInputMode()->viewInputMode() == mode) {
1601 clearSecondaryCursors();
1604 m_viewInternal->m_currentInputMode->deactivate();
1605 m_viewInternal->m_currentInputMode = m_viewInternal->m_inputModes[mode].get();
1606 m_viewInternal->m_currentInputMode->activate();
1609 if (rememberInConfig) {
1610 config()->setValue(KateViewConfig::InputMode, mode);
1614 const auto inputModeActions = m_inputModeActions->actions();
1615 for (
QAction *action : inputModeActions) {
1616 if (
static_cast<InputMode
>(action->data().toInt()) == mode) {
1617 action->setChecked(
true);
1623 Q_EMIT viewInputModeChanged(
this, mode);
1624 Q_EMIT viewModeChanged(
this, viewMode());
1627void KTextEditor::ViewPrivate::slotDocumentAboutToReload()
1629 if (doc()->isAutoReload()) {
1630 const int lastVisibleLine = m_viewInternal->endLine();
1631 const int currentLine = cursorPosition().line();
1632 m_gotoBottomAfterReload = (lastVisibleLine == currentLine) && (currentLine == doc()->lastLine());
1633 if (!m_gotoBottomAfterReload) {
1635 const int firstVisibleLine = 1 + lastVisibleLine - m_viewInternal->linesDisplayed();
1636 const int newLine = qBound(firstVisibleLine, currentLine, lastVisibleLine);
1640 m_gotoBottomAfterReload =
false;
1644void KTextEditor::ViewPrivate::slotDocumentReloaded()
1646 if (m_gotoBottomAfterReload) {
1651void KTextEditor::ViewPrivate::slotGotFocus()
1654 currentInputMode()->gotFocus();
1660 if (m_viewInternal->m_lineScroll->isVisible()) {
1661 m_viewInternal->m_lineScroll->update();
1664 if (m_viewInternal->m_columnScroll->isVisible()) {
1665 m_viewInternal->m_columnScroll->update();
1671void KTextEditor::ViewPrivate::slotLostFocus()
1674 currentInputMode()->lostFocus();
1680 if (m_viewInternal->m_lineScroll->isVisible()) {
1681 m_viewInternal->m_lineScroll->update();
1684 if (m_viewInternal->m_columnScroll->isVisible()) {
1685 m_viewInternal->m_columnScroll->update();
1688 if (doc()->config()->autoSave() && doc()->config()->autoSaveOnFocusOut() && doc()->isModified() && doc()->url().isLocalFile()) {
1689 doc()->documentSave();
1695void KTextEditor::ViewPrivate::setDynWrapIndicators(
int mode)
1697 config()->setValue(KateViewConfig::DynWordWrapIndicators, mode);
1700bool KTextEditor::ViewPrivate::isOverwriteMode()
const
1702 return doc()->
config()->ovr();
1705void KTextEditor::ViewPrivate::reloadFile()
1711void KTextEditor::ViewPrivate::slotReadWriteChanged()
1713 if (m_toggleWriteLock) {
1714 m_toggleWriteLock->setChecked(!doc()->isReadWrite());
1717 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
1718 m_paste->setEnabled(doc()->isReadWrite());
1719 if (m_pasteSelection) {
1720 m_pasteSelection->setEnabled(doc()->isReadWrite());
1722 m_swapWithClipboard->setEnabled(doc()->isReadWrite());
1723 m_setEndOfLine->setEnabled(doc()->isReadWrite());
1725 static const auto l = {QStringLiteral(
"edit_replace"),
1726 QStringLiteral(
"tools_spelling"),
1727 QStringLiteral(
"tools_indent"),
1728 QStringLiteral(
"tools_unindent"),
1729 QStringLiteral(
"tools_cleanIndent"),
1730 QStringLiteral(
"tools_formatIndet"),
1731 QStringLiteral(
"tools_alignOn"),
1732 QStringLiteral(
"tools_comment"),
1733 QStringLiteral(
"tools_uncomment"),
1734 QStringLiteral(
"tools_toggle_comment"),
1735 QStringLiteral(
"tools_uppercase"),
1736 QStringLiteral(
"tools_lowercase"),
1737 QStringLiteral(
"tools_capitalize"),
1738 QStringLiteral(
"tools_join_lines"),
1739 QStringLiteral(
"tools_apply_wordwrap"),
1740 QStringLiteral(
"tools_spelling_from_cursor"),
1741 QStringLiteral(
"tools_spelling_selection")};
1743 for (
const auto &action : l) {
1744 QAction *a = actionCollection()->action(action);
1751 currentInputMode()->readWriteChanged(doc()->isReadWrite());
1754 Q_EMIT viewModeChanged(
this, viewMode());
1755 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1758void KTextEditor::ViewPrivate::toggleCamelCaseCursor()
1760 const auto enabled = doc()->
config()->camelCursor();
1761 doc()->
config()->setCamelCursor(!enabled);
1774void KTextEditor::ViewPrivate::slotUpdateUndo()
1776 if (doc()->readOnly()) {
1780 m_editUndo->setEnabled(doc()->isReadWrite() && doc()->undoCount() > 0);
1781 m_editRedo->setEnabled(doc()->isReadWrite() && doc()->redoCount() > 0);
1784bool KTextEditor::ViewPrivate::setCursorPositionInternal(
const KTextEditor::Cursor position, uint tabwidth,
bool calledExternally)
1786 if (position.
line() < 0 || position.
line() >= doc()->lines()) {
1795 for (; z < line_str.
length() && z < position.
column(); z++) {
1797 x += tabwidth - (x % tabwidth);
1803 if (blockSelection()) {
1804 if (z < position.
column()) {
1805 x += position.
column() - z;
1817void KTextEditor::ViewPrivate::toggleInsert()
1819 doc()->
config()->setOvr(!doc()->config()->ovr());
1820 m_toggleInsert->setChecked(isOverwriteMode());
1823 if (isOverwriteMode()) {
1824 clearSecondaryCursors();
1827 Q_EMIT viewModeChanged(
this, viewMode());
1828 Q_EMIT viewInputModeChanged(
this, viewInputMode());
1831void KTextEditor::ViewPrivate::slotSaveCanceled(
const QString &error)
1833 if (!
error.isEmpty()) {
1838void KTextEditor::ViewPrivate::gotoLine()
1840 gotoBar()->updateData();
1841 bottomViewBar()->showBarWidget(gotoBar());
1844void KTextEditor::ViewPrivate::changeDictionary()
1846 dictionaryBar()->updateData();
1847 bottomViewBar()->showBarWidget(dictionaryBar());
1850void KTextEditor::ViewPrivate::joinLines()
1852 int first = selectionRange().start().line();
1853 int last = selectionRange().end().line();
1855 if (first == last) {
1856 first = cursorPosition().line();
1868 setCursorPositionInternal(savedPosition);
1871 const int scroll = config.
readEntry(
"ScrollLine", -1);
1872 if (scroll >= 0 && scroll < doc()->lines() && savedPosition.
line() < doc()->lines()) {
1877 if (config.
hasKey(
"Dynamic Word Wrap")) {
1879 m_config->setDynWordWrap(config.
readEntry(
"Dynamic Word Wrap", m_config->global()->dynWordWrap()));
1884 applyFoldingState();
1886 m_forceRTL = config.
readEntry(
"Force RTL Direction",
false);
1887 m_forceRTLDirection->setChecked(m_forceRTL);
1889 for (
const auto &mode : m_viewInternal->m_inputModes) {
1890 mode->readSessionConfig(config);
1900 const auto cursor = cursorPosition();
1902 config.
writeEntry(
"CursorLine", cursor.line());
1903 config.
writeEntry(
"CursorColumn", cursor.column());
1907 const int scrollLine = firstDisplayedLineInternal(LineType::RealLine);
1908 if (scrollLine > 0 && scrollLine != cursor.line()) {
1913 if (m_config->isSet(KateViewConfig::DynamicWordWrap)) {
1914 config.
writeEntry(
"Dynamic Word Wrap", m_config->dynWordWrap());
1919 if (!m_savedFoldingState.object().value(
QLatin1String(
"ranges")).toArray().isEmpty()) {
1925 config.
writeEntry(
"Force RTL Direction", m_forceRTL);
1928 for (
const auto &mode : m_viewInternal->m_inputModes) {
1929 mode->writeSessionConfig(config);
1933int KTextEditor::ViewPrivate::getEol()
const
1935 return doc()->
config()->eol();
1938QMenu *KTextEditor::ViewPrivate::getEolMenu()
1940 return m_setEndOfLine->menu();
1943void KTextEditor::ViewPrivate::setEol(
int eol)
1945 if (!doc()->isReadWrite()) {
1949 if (m_updatingDocumentConfig) {
1953 if (eol != doc()->config()->eol()) {
1954 doc()->setModified(
true);
1955 doc()->
config()->setEol(eol);
1959void KTextEditor::ViewPrivate::setAddBom(
bool enabled)
1961 if (!doc()->isReadWrite()) {
1965 if (m_updatingDocumentConfig) {
1969 doc()->
config()->setBom(enabled);
1973void KTextEditor::ViewPrivate::setIconBorder(
bool enable)
1975 config()->setValue(KateViewConfig::ShowIconBar, enable);
1978void KTextEditor::ViewPrivate::toggleIconBorder()
1980 config()->setValue(KateViewConfig::ShowIconBar, !config()->iconBar());
1983void KTextEditor::ViewPrivate::setLineNumbersOn(
bool enable)
1985 config()->setValue(KateViewConfig::ShowLineNumbers, enable);
1988void KTextEditor::ViewPrivate::toggleLineNumbersOn()
1990 config()->setValue(KateViewConfig::ShowLineNumbers, !config()->lineNumbers());
1993void KTextEditor::ViewPrivate::setScrollBarMarks(
bool enable)
1995 config()->setValue(KateViewConfig::ShowScrollBarMarks, enable);
1998void KTextEditor::ViewPrivate::toggleScrollBarMarks()
2000 config()->setValue(KateViewConfig::ShowScrollBarMarks, !config()->scrollBarMarks());
2003void KTextEditor::ViewPrivate::setScrollBarMiniMap(
bool enable)
2005 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, enable);
2008void KTextEditor::ViewPrivate::toggleScrollBarMiniMap()
2010 config()->setValue(KateViewConfig::ShowScrollBarMiniMap, !config()->scrollBarMiniMap());
2013void KTextEditor::ViewPrivate::setScrollBarMiniMapAll(
bool enable)
2015 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, enable);
2018void KTextEditor::ViewPrivate::toggleScrollBarMiniMapAll()
2020 config()->setValue(KateViewConfig::ShowScrollBarMiniMapAll, !config()->scrollBarMiniMapAll());
2023void KTextEditor::ViewPrivate::setScrollBarMiniMapWidth(
int width)
2025 config()->setValue(KateViewConfig::ScrollBarMiniMapWidth, width);
2028void KTextEditor::ViewPrivate::toggleShowSpaces()
2030 if (m_updatingDocumentConfig) {
2034 using WhitespaceRendering = KateDocumentConfig::WhitespaceRendering;
2035 doc()->
config()->setShowSpaces(doc()->config()->showSpaces() != WhitespaceRendering::None ? WhitespaceRendering::None : WhitespaceRendering::All);
2038void KTextEditor::ViewPrivate::toggleDynWordWrap()
2040 config()->setDynWordWrap(!config()->dynWordWrap());
2043void KTextEditor::ViewPrivate::toggleWWMarker()
2045 m_renderer->config()->setWordWrapMarker(!m_renderer->config()->wordWrapMarker());
2048void KTextEditor::ViewPrivate::toggleNPSpaces()
2050 m_renderer->setShowNonPrintableSpaces(!m_renderer->showNonPrintableSpaces());
2051 m_viewInternal->update();
2054void KTextEditor::ViewPrivate::toggleWordCount(
bool on)
2056 config()->setShowWordCount(on);
2059void KTextEditor::ViewPrivate::setFoldingMarkersOn(
bool enable)
2061 config()->setValue(KateViewConfig::ShowFoldingBar, enable);
2064void KTextEditor::ViewPrivate::toggleFoldingMarkers()
2066 config()->setValue(KateViewConfig::ShowFoldingBar, !config()->foldingBar());
2069bool KTextEditor::ViewPrivate::iconBorder()
2071 return m_viewInternal->m_leftBorder->iconBorderOn();
2074bool KTextEditor::ViewPrivate::lineNumbersOn()
2076 return m_viewInternal->m_leftBorder->lineNumbersOn();
2079bool KTextEditor::ViewPrivate::scrollBarMarks()
2081 return m_viewInternal->m_lineScroll->showMarks();
2084bool KTextEditor::ViewPrivate::scrollBarMiniMap()
2086 return m_viewInternal->m_lineScroll->showMiniMap();
2089int KTextEditor::ViewPrivate::dynWrapIndicators()
2091 return m_viewInternal->m_leftBorder->dynWrapIndicators();
2094bool KTextEditor::ViewPrivate::foldingMarkersOn()
2096 return m_viewInternal->m_leftBorder->foldingMarkersOn();
2099bool KTextEditor::ViewPrivate::forceRTLDirection()
const
2104void KTextEditor::ViewPrivate::toggleWriteLock()
2106 doc()->setReadWrite(!doc()->isReadWrite());
2111 m_viewInternal->registerTextHintProvider(provider);
2116 m_viewInternal->unregisterTextHintProvider(provider);
2119void KTextEditor::ViewPrivate::setTextHintDelay(
int delay)
2121 m_viewInternal->setTextHintDelay(delay);
2124int KTextEditor::ViewPrivate::textHintDelay()
const
2126 return m_viewInternal->textHintDelay();
2130void KTextEditor::ViewPrivate::find()
2132 currentInputMode()->find();
2136void KTextEditor::ViewPrivate::findSelectedForwards()
2138 currentInputMode()->findSelectedForwards();
2142void KTextEditor::ViewPrivate::findSelectedBackwards()
2144 currentInputMode()->findSelectedBackwards();
2147void KTextEditor::ViewPrivate::skipCurrentOccurunceSelection()
2149 if (isMulticursorNotAllowed()) {
2152 m_skipCurrentSelection =
true;
2155void KTextEditor::ViewPrivate::findNextOccurunceAndSelect()
2157 if (isMulticursorNotAllowed()) {
2161 const auto text = selection() ? doc()->
text(selectionRange()) :
QString();
2162 if (text.isEmpty()) {
2163 const auto selection = doc()->
wordRangeAt(cursorPosition());
2165 setSelection(selection);
2166 setCursorPosition(selection.end());
2169 for (
auto &c : m_secondaryCursors) {
2170 const auto range = doc()->
wordRangeAt(c.cursor());
2171 if (!c.range && !c.anchor.isValid()) {
2172 c.anchor = range.
start();
2173 c.range.reset(newSecondarySelectionRange(range));
2179 }
else if (!m_rangesForHighlights.empty()) {
2184 const auto lastSelectionRange = selectionRange();
2189 searchRange.setRange(doc()->documentRange().
start(), lastSelectionRange.end());
2198 auto it = std::find_if(m_secondaryCursors.begin(), m_secondaryCursors.end(), [&](
const SecondaryCursor &c) {
2199 return c.range && c.range->toRange() == matches.constFirst();
2202 if (it != m_secondaryCursors.end()) {
2203 m_secondaryCursors.erase(it);
2209 setCursorPosition(matches.
constFirst().end());
2213 if (!m_skipCurrentSelection) {
2214 PlainSecondaryCursor c;
2215 c.pos = lastSelectionRange.end();
2216 c.range = lastSelectionRange;
2218 addSecondaryCursorsWithSelection({c});
2221 m_skipCurrentSelection =
false;
2224void KTextEditor::ViewPrivate::findAllOccuruncesAndSelect()
2226 if (isMulticursorNotAllowed()) {
2232 const auto selection = doc()->
wordRangeAt(cursorPosition());
2233 setSelection(selection);
2234 setCursorPosition(selection.end());
2236 text = doc()->
text(selection);
2238 for (
auto &c : m_secondaryCursors) {
2239 const auto range = doc()->
wordRangeAt(c.cursor());
2240 if (!c.range && !c.anchor.isValid()) {
2241 c.anchor = range.
start();
2242 c.range.reset(newSecondarySelectionRange(range));
2257 if (matches.
constFirst() != selectionRange()) {
2258 PlainSecondaryCursor c;
2263 searchRange.setStart(matches.
constFirst().end());
2265 }
while (matches.
first().isValid());
2268 if (!resultRanges.
empty()) {
2272 clearSecondaryCursors();
2273 addSecondaryCursorsWithSelection(resultRanges);
2277void KTextEditor::ViewPrivate::replace()
2279 currentInputMode()->findReplace();
2283void KTextEditor::ViewPrivate::findNext()
2285 currentInputMode()->findNext();
2289void KTextEditor::ViewPrivate::findPrevious()
2291 currentInputMode()->findPrevious();
2294void KTextEditor::ViewPrivate::showSearchWrappedHint(
bool isReverseSearch)
2297 const QIcon icon = isReverseSearch ?
QIcon::fromTheme(QStringLiteral(
"go-up-search")) :
QIcon::fromTheme(QStringLiteral(
"go-down-search"));
2299 if (!m_wrappedMessage || m_isLastSearchReversed != isReverseSearch) {
2300 m_isLastSearchReversed = isReverseSearch;
2302 m_wrappedMessage->setIcon(icon);
2304 m_wrappedMessage->setAutoHide(2000);
2306 m_wrappedMessage->setView(
this);
2311void KTextEditor::ViewPrivate::createMultiCursorsFromSelection()
2313 if (!selection() || selectionRange().isEmpty()) {
2318 clearSecondaryCursors();
2320 const auto range = selectionRange();
2324 const auto currentLine = cursorPosition().line();
2325 setCursorPosition({currentLine, doc()->
lineLength(currentLine)});
2326 for (
int line =
start; line <=
end; ++line) {
2327 if (line != currentLine) {
2333 setSecondaryCursors(cursorsToAdd);
2336void KTextEditor::ViewPrivate::removeCursorsFromEmptyLines()
2338 if (!m_secondaryCursors.empty()) {
2339 std::vector<KTextEditor::Cursor> cursorsToRemove;
2340 for (
const auto &c : m_secondaryCursors) {
2341 auto cursor = c.cursor();
2342 if (doc()->lineLength(cursor.line()) == 0) {
2343 cursorsToRemove.push_back(cursor);
2346 removeSecondaryCursors(cursorsToRemove);
2350void KTextEditor::ViewPrivate::slotSelectionChanged()
2352 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2353 m_deSelect->setEnabled(selection());
2354 m_copyHtmlAction->setEnabled(selection());
2357 selectionChangedForHighlights();
2359 if (doc()->readOnly()) {
2363 m_cut->setEnabled(selection() || m_config->smartCopyCut());
2364 m_screenshotSelection->setVisible(selection());
2365 m_screenshotSelection->setEnabled(selection());
2369void KTextEditor::ViewPrivate::switchToCmdLine()
2371 currentInputMode()->activateCommandLine();
2379KateRendererConfig *KTextEditor::ViewPrivate::rendererConfig()
2381 return m_renderer->config();
2384void KTextEditor::ViewPrivate::updateConfig()
2390 m_toggleShowSpace->setChecked(doc()->config()->showSpaces() != KateDocumentConfig::WhitespaceRendering::None);
2393 if (m_hasWrap != config()->dynWordWrap()) {
2394 m_hasWrap = config()->dynWordWrap();
2396 m_viewInternal->dynWrapChanged();
2398 m_setDynWrapIndicators->setEnabled(config()->dynWordWrap());
2399 m_toggleDynWrap->setChecked(config()->dynWordWrap());
2402 m_viewInternal->m_leftBorder->setDynWrapIndicators(config()->dynWordWrapIndicators());
2403 m_setDynWrapIndicators->setCurrentItem(config()->dynWordWrapIndicators());
2406 m_viewInternal->m_leftBorder->setLineNumbersOn(config()->lineNumbers());
2407 m_toggleLineNumbers->setChecked(config()->lineNumbers());
2410 m_viewInternal->m_leftBorder->setIconBorderOn(config()->iconBar());
2411 m_toggleIconBar->setChecked(config()->iconBar());
2414 m_viewInternal->m_lineScroll->setShowMarks(config()->scrollBarMarks());
2415 m_toggleScrollBarMarks->setChecked(config()->scrollBarMarks());
2418 m_viewInternal->m_lineScroll->setShowMiniMap(config()->scrollBarMiniMap());
2419 m_toggleScrollBarMiniMap->setChecked(config()->scrollBarMiniMap());
2422 m_viewInternal->m_lineScroll->setMiniMapAll(config()->scrollBarMiniMapAll());
2426 m_viewInternal->m_lineScroll->setMiniMapWidth(config()->scrollBarMiniMapWidth());
2429 m_toggleBlockSelection->setChecked(blockSelection());
2430 m_toggleInsert->setChecked(isOverwriteMode());
2432 updateFoldingConfig();
2435 m_bookmarks->setSorting((KateBookmarks::Sorting)config()->bookmarkSort());
2437 m_viewInternal->setAutoCenterLines(config()->autoCenterLines());
2439 for (
const auto &input : m_viewInternal->m_inputModes) {
2440 input->updateConfig();
2443 setInputMode(config()->inputMode(),
false );
2445 reflectOnTheFlySpellCheckStatus(doc()->isOnTheFlySpellCheckingEnabled());
2448 bool wc = config()->wordCompletion();
2457 bool kc = config()->keywordCompletion();
2466 m_cut->setEnabled(doc()->isReadWrite() && (selection() || m_config->smartCopyCut()));
2467 m_copy->setEnabled(selection() || m_config->smartCopyCut());
2469 m_accessibilityEnabled = m_config->value(KateViewConfig::EnableAccessibility).toBool();
2473 m_statusBar->updateStatus();
2477 m_viewInternal->cache()->clear();
2481 Q_EMIT configChanged(
this);
2484void KTextEditor::ViewPrivate::updateDocumentConfig()
2490 m_updatingDocumentConfig =
true;
2492 m_setEndOfLine->setCurrentItem(doc()->config()->eol());
2494 m_addBom->setChecked(doc()->config()->
bom());
2496 m_updatingDocumentConfig =
false;
2499 ensureCursorColumnValid();
2502 m_renderer->setTabWidth(doc()->config()->tabWidth());
2503 m_renderer->setIndentWidth(doc()->config()->indentationWidth());
2506 m_viewInternal->cache()->clear();
2511void KTextEditor::ViewPrivate::updateRendererConfig()
2517 m_toggleWWMarker->setChecked(m_renderer->config()->wordWrapMarker());
2519 m_viewInternal->updateBracketMarkAttributes();
2520 m_viewInternal->updateBracketMarks();
2523 m_viewInternal->cache()->clear();
2525 m_viewInternal->updateView(
true);
2528 m_viewInternal->m_leftBorder->updateFont();
2529 m_viewInternal->m_leftBorder->repaint();
2531 m_viewInternal->m_lineScroll->queuePixmapUpdate();
2533 currentInputMode()->updateRendererConfig();
2537 Q_EMIT configChanged(
this);
2540void KTextEditor::ViewPrivate::updateFoldingConfig()
2543 m_viewInternal->m_leftBorder->setFoldingMarkersOn(config()->foldingBar());
2544 m_toggleFoldingMarkers->setChecked(config()->foldingBar());
2546 if (hasCommentInFirstLine(m_doc)) {
2547 if (config()->foldFirstLine() && !m_autoFoldedFirstLine) {
2549 m_autoFoldedFirstLine =
true;
2550 }
else if (!config()->foldFirstLine() && m_autoFoldedFirstLine) {
2552 m_autoFoldedFirstLine =
false;
2555 m_autoFoldedFirstLine =
false;
2561 QStringLiteral(
"folding_toplevel")
2562 , QStringLiteral(
"folding_expandtoplevel")
2563 , QStringLiteral(
"folding_toggle_current")
2564 , QStringLiteral(
"folding_toggle_in_current")
2568 for (
int z = 0; z < l.
size(); z++)
2569 if ((a = actionCollection()->action(l[z].toAscii().constData()))) {
2570 a->
setEnabled(doc()->highlight() && doc()->highlight()->allowsFolding());
2575void KTextEditor::ViewPrivate::ensureCursorColumnValid()
2582 if (!blockSelection() && wrapCursor() && (!c.
isValid() || c.
column() > doc()->lineLength(c.
line()))) {
2583 c.
setColumn(doc()->lineLength(cursorPosition().line()));
2584 setCursorPosition(c);
2589void KTextEditor::ViewPrivate::editStart()
2591 m_viewInternal->editStart();
2594void KTextEditor::ViewPrivate::editEnd(
int editTagLineStart,
int editTagLineEnd,
bool tagFrom)
2596 m_viewInternal->editEnd(editTagLineStart, editTagLineEnd, tagFrom);
2597 textFolding().editEnd(editTagLineStart, editTagLineEnd, [
this](
int line) {
2598 return m_doc->buffer().isFoldingStartingOnLine(line).first;
2604 m_viewInternal->editSetCursor(cursor);
2611 return m_viewInternal->tagLine(virtualCursor);
2616 return m_viewInternal->tagRange(range, realLines);
2621 return m_viewInternal->tagLines(lineRange.
start(), lineRange.
end(), realLines);
2626 return m_viewInternal->tagLines(
start, end, realCursors);
2629void KTextEditor::ViewPrivate::tagAll()
2631 m_viewInternal->tagAll();
2634void KTextEditor::ViewPrivate::clear()
2636 m_viewInternal->clear();
2639void KTextEditor::ViewPrivate::repaintText(
bool paintOnlyDirty)
2641 if (paintOnlyDirty) {
2642 m_viewInternal->updateDirty();
2644 m_viewInternal->update();
2648void KTextEditor::ViewPrivate::updateView(
bool changed)
2651 m_viewInternal->updateView(changed);
2652 m_viewInternal->m_leftBorder->update();
2657void KTextEditor::ViewPrivate::slotHlChanged()
2659 KateHighlighting *hl = doc()->highlight();
2660 bool ok(!hl->getCommentStart(0).
isEmpty() || !hl->getCommentSingleLineStart(0).
isEmpty());
2662 if (actionCollection()->action(QStringLiteral(
"tools_comment"))) {
2663 actionCollection()->action(QStringLiteral(
"tools_comment"))->setEnabled(ok);
2666 if (actionCollection()->action(QStringLiteral(
"tools_uncomment"))) {
2667 actionCollection()->action(QStringLiteral(
"tools_uncomment"))->setEnabled(ok);
2670 if (actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))) {
2671 actionCollection()->action(QStringLiteral(
"tools_toggle_comment"))->setEnabled(ok);
2675 updateFoldingConfig();
2678int KTextEditor::ViewPrivate::virtualCursorColumn()
const
2680 return doc()->toVirtualColumn(m_viewInternal->cursorPosition());
2683void KTextEditor::ViewPrivate::notifyMousePositionChanged(
const KTextEditor::Cursor newPosition)
2685 Q_EMIT mousePositionChanged(
this, newPosition);
2693 if (selection == m_selection) {
2704 tagSelection(oldSelection);
2708 Q_EMIT selectionChanged(
this);
2714bool KTextEditor::ViewPrivate::clearSelection()
2716 return clearSelection(
true);
2719bool KTextEditor::ViewPrivate::clearSelection(
bool redraw,
bool finishedChangingSelection)
2733 tagSelection(oldSelection);
2739 if (finishedChangingSelection) {
2740 Q_EMIT selectionChanged(
this);
2743 m_viewInternal->m_selChangedByUser =
false;
2748bool KTextEditor::ViewPrivate::selection()
const
2750 if (!wrapCursor()) {
2753 return m_selection.toRange().isValid();
2757QString KTextEditor::ViewPrivate::selectionText()
const
2760 return doc()->
text(m_selection, blockSelect);
2764 for (
const auto &c : m_secondaryCursors) {
2769 ranges.
push_back(m_selection.toRange());
2770 std::sort(ranges.
begin(), ranges.
end());
2773 text.
reserve(ranges.
size() * m_selection.toRange().columnWidth());
2774 for (
int i = 0; i < ranges.
size() - 1; ++i) {
2775 text += doc()->
text(ranges[i]) + QStringLiteral(
"\n");
2777 text += doc()->
text(ranges.
last());
2782bool KTextEditor::ViewPrivate::removeSelectedText()
2784 if (!hasSelections()) {
2790 bool removed =
false;
2793 completionWidget()->setIgnoreBufferSignals(
true);
2794 for (
auto &c : m_secondaryCursors) {
2797 doc()->removeText(c.range->toRange());
2801 completionWidget()->setIgnoreBufferSignals(
false);
2809 doc()->removeText(selection, blockSelect);
2814 int selectionColumn = qMin(doc()->toVirtualColumn(selection.
start()), doc()->toVirtualColumn(selection.
end()));
2818 setSelection(newSelection);
2819 setCursorPositionInternal(newSelection.
start());
2821 clearSecondarySelections();
2822 clearSelection(
false);
2828bool KTextEditor::ViewPrivate::selectAll()
2830 clearSecondaryCursors();
2831 setBlockSelection(
false);
2838 setSelection(doc()->documentRange());
2839 m_viewInternal->moveCursorToSelectionEdge(
false);
2840 m_viewInternal->updateMicroFocus();
2847 if ((!blockSelect) && (ret.
column() < 0)) {
2852 return cursor.
line() >= m_selection.start().line() && ret.
line() <= m_selection.end().line() && ret.
column() >= m_selection.start().column()
2853 && ret.
column() <= m_selection.end().column();
2855 return m_selection.toRange().contains(cursor) || m_selection.end() == cursor;
2859bool KTextEditor::ViewPrivate::lineSelected(
int line)
2861 return !blockSelect && m_selection.toRange().containsLine(line);
2866 return (!blockSelect)
2867 && (lineEndPos.
line() > m_selection.start().line()
2868 || (lineEndPos.
line() == m_selection.start().line() && (m_selection.start().column() < lineEndPos.
column() || lineEndPos.
column() == -1)))
2869 && (lineEndPos.
line() < m_selection.end().line()
2870 || (lineEndPos.
line() == m_selection.end().line() && (lineEndPos.
column() <= m_selection.end().column() && lineEndPos.
column() != -1)));
2873bool KTextEditor::ViewPrivate::lineHasSelected(
int line)
2875 return selection() && m_selection.toRange().
containsLine(line);
2878bool KTextEditor::ViewPrivate::lineIsSelection(
int line)
2880 return (line == m_selection.start().line() && line == m_selection.end().line());
2886 if (oldSelection.
start().
line() == -1) {
2890 tagLines(m_selection,
true);
2892 }
else if (blockSelection()
2893 && (oldSelection.
start().
column() != m_selection.start().column() || oldSelection.
end().
column() != m_selection.end().column())) {
2895 tagLines(m_selection,
true);
2896 tagLines(oldSelection,
true);
2899 if (oldSelection.
start() != m_selection.
start()) {
2903 if (oldSelection.
end() != m_selection.end()) {
2910 tagLines(oldSelection,
true);
2916 setSelection(doc()->wordRangeAt(cursor));
2921 int line = cursor.
line();
2922 if (line + 1 >= doc()->lines()) {
2929void KTextEditor::ViewPrivate::cut()
2931 if (!selection() && !m_config->smartCopyCut()) {
2937 m_markedSelection =
false;
2941 selectLine(cursorPosition());
2943 removeSelectedText();
2946void KTextEditor::ViewPrivate::copy()
2952 if (!m_config->smartCopyCut()) {
2956 m_viewInternal->moveEdge(KateViewInternal::left,
false);
2958 text = selectionText();
2961 if (!m_secondaryCursors.empty()) {
2963 for (
const auto &c : m_secondaryCursors) {
2968 ranges.
push_back(m_selection.toRange());
2969 std::sort(ranges.
begin(), ranges.
end());
2971 for (
auto range : ranges) {
2972 texts.
append(doc()->text(range));
2977 if (m_markedSelection) {
2979 m_markedSelection =
false;
2987void KTextEditor::ViewPrivate::screenshot()
2993 ScreenshotDialog d(selectionRange(),
this);
2994 d.renderScreenshot(m_renderer);
2998void KTextEditor::ViewPrivate::pasteSelection()
3000 m_temporaryAutomaticInvocationDisabled =
true;
3002 m_temporaryAutomaticInvocationDisabled =
false;
3005void KTextEditor::ViewPrivate::swapWithClipboard()
3007 m_temporaryAutomaticInvocationDisabled =
true;
3016 doc()->paste(
this, text);
3018 m_temporaryAutomaticInvocationDisabled =
false;
3021void KTextEditor::ViewPrivate::applyWordWrap()
3023 int first = selectionRange().start().line();
3024 int last = selectionRange().end().line();
3026 if (first == last) {
3028 first = cursorPosition().line();
3039bool KTextEditor::ViewPrivate::blockSelection()
const
3044bool KTextEditor::ViewPrivate::setBlockSelection(
bool on)
3046 if (on != blockSelect) {
3051 const bool hadSelection = clearSelection(
false,
false);
3053 setSelection(oldSelection);
3055 m_toggleBlockSelection->setChecked(blockSelection());
3059 ensureCursorColumnValid();
3061 if (!hadSelection) {
3066 Q_EMIT selectionChanged(
this);
3073bool KTextEditor::ViewPrivate::toggleBlockSelection()
3076 clearSecondaryCursors();
3078 m_toggleBlockSelection->setChecked(!blockSelect);
3079 return setBlockSelection(!blockSelect);
3082bool KTextEditor::ViewPrivate::wrapCursor()
const
3084 return !blockSelection();
3091 Q_EMIT textInserted(view, position, text);
3097 if (templateString.
isEmpty()) {
3102 if (!doc()->isReadWrite()) {
3108 doc()->setActiveTemplateHandler(
nullptr);
3109 doc()->setActiveTemplateHandler(
new KateTemplateHandler(
this, c, templateString, script, doc()->undoManager()));
3115 return tagLines(range.
start(), range.
end(), realRange);
3118void KTextEditor::ViewPrivate::deactivateEditActions()
3120 for (
QAction *action : std::as_const(m_editActions)) {
3121 action->setEnabled(
false);
3125void KTextEditor::ViewPrivate::activateEditActions()
3127 for (
QAction *action : std::as_const(m_editActions)) {
3128 action->setEnabled(
true);
3132bool KTextEditor::ViewPrivate::mouseTrackingEnabled()
const
3138bool KTextEditor::ViewPrivate::setMouseTrackingEnabled(
bool)
3144bool KTextEditor::ViewPrivate::isMulticursorNotAllowed()
const
3151 auto primaryCursor = cursorPosition();
3152 const bool overlapsOrOnPrimary = pos == primaryCursor || (selection() && selectionRange().
contains(pos));
3153 if (overlapsOrOnPrimary && m_secondaryCursors.empty()) {
3157 }
else if (overlapsOrOnPrimary) {
3161 auto &last = m_secondaryCursors.back();
3162 setCursorPosition(last.cursor());
3164 setSelection(last.range->toRange());
3165 Q_ASSERT(last.anchor.isValid());
3166 m_viewInternal->m_selectAnchor = last.anchor;
3168 m_secondaryCursors.pop_back();
3175 if (removeSecondaryCursors({pos},
true)) {
3183 setCursorPosition(pos);
3184 KTextEditor::ViewPrivate::PlainSecondaryCursor p;
3185 p.pos = primaryCursor;
3188 addSecondaryCursorsWithSelection({p});
3193 clearSecondaryCursors();
3195 if (positions.
isEmpty() || isMulticursorNotAllowed()) {
3199 const auto totalLines = doc()->
lines();
3200 for (
auto p : positions) {
3201 if (p != cursorPosition() && p.line() < totalLines) {
3204 m_secondaryCursors.push_back(std::move(c));
3212void KTextEditor::ViewPrivate::clearSecondarySelections()
3214 for (
auto &c : m_secondaryCursors) {
3219void KTextEditor::ViewPrivate::clearSecondaryCursors()
3221 if (m_secondaryCursors.empty()) {
3224 for (
const auto &c : m_secondaryCursors) {
3225 tagLine(c.cursor());
3227 m_secondaryCursors.clear();
3228 m_viewInternal->updateDirty();
3231const std::vector<KTextEditor::ViewPrivate::SecondaryCursor> &KTextEditor::ViewPrivate::secondaryCursors()
const
3233 return m_secondaryCursors;
3239 cursors.
reserve(m_secondaryCursors.size());
3240 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(cursors), [](
const SecondaryCursor &c) {
3242 return PlainSecondaryCursor{.pos = c.cursor(), .range = c.range->toRange()};
3244 return PlainSecondaryCursor{.pos = c.cursor(), .range = KTextEditor::Range::invalid()};
3249bool KTextEditor::ViewPrivate::removeSecondaryCursors(
const std::vector<KTextEditor::Cursor> &cursorsToRemove,
bool removeIfOverlapsSelection)
3251 Q_ASSERT(std::is_sorted(cursorsToRemove.begin(), cursorsToRemove.end()));
3255 if (removeIfOverlapsSelection) {
3256 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3257 m_secondaryCursors.end(),
3258 [&](
const SecondaryCursor &c) {
3259 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3260 return c.cursor() == pos || (c.range && c.range->contains(pos));
3262 const bool match = it != cursorsToRemove.end();
3268 m_secondaryCursors.
end());
3270 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3271 m_secondaryCursors.end(),
3272 [&](
const SecondaryCursor &c) {
3273 auto it = std::find_if(cursorsToRemove.begin(), cursorsToRemove.end(), [&c](KTextEditor::Cursor pos) {
3274 return c.cursor() == pos;
3276 const bool match = it != cursorsToRemove.end();
3282 m_secondaryCursors.end());
3285 for (
const auto &c : linesToTag) {
3286 tagLine(m_viewInternal->toVirtualCursor(c));
3288 return !linesToTag.
empty();
3290 for (
auto cur : cursorsToRemove) {
3291 auto &sec = m_secondaryCursors;
3292 auto it = std::find_if(sec.begin(), sec.end(), [cur](
const SecondaryCursor &c) {
3293 return c.cursor() == cur;
3295 if (it != sec.end()) {
3297 m_secondaryCursors.erase(it);
3298 tagLine(m_viewInternal->toVirtualCursor(cur));
3303 m_viewInternal->updateDirty();
3305 m_viewInternal->paintCursor();
3307 return !linesToTag.
empty();
3312void KTextEditor::ViewPrivate::ensureUniqueCursors(
bool matchLine)
3314 if (m_secondaryCursors.empty()) {
3318 std::vector<SecondaryCursor>::iterator it;
3320 auto matchLine = [](
const SecondaryCursor &l,
const SecondaryCursor &r) {
3321 return l.cursor().line() == r.cursor().line();
3323 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end(), matchLine);
3325 it = std::unique(m_secondaryCursors.begin(), m_secondaryCursors.end());
3327 if (it != m_secondaryCursors.end()) {
3328 m_secondaryCursors.erase(it, m_secondaryCursors.end());
3332 const int ln = cursorPosition().line();
3333 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3334 m_secondaryCursors.end(),
3335 [ln](
const SecondaryCursor &c) {
3336 return c.cursor().line() == ln;
3338 m_secondaryCursors.end());
3340 const auto cp = cursorPosition();
3341 const auto sel = selectionRange();
3342 m_secondaryCursors.erase(std::remove_if(m_secondaryCursors.begin(),
3343 m_secondaryCursors.end(),
3344 [cp, sel](
const SecondaryCursor &c) {
3345 return c.cursor() == cp && c.selectionRange() == sel;
3347 m_secondaryCursors.end());
3353 if (isMulticursorNotAllowed() || cursorsWithSelection.
isEmpty()) {
3357 for (
const auto &c : cursorsWithSelection) {
3359 if (c.pos == cursorPosition()) {
3363 n.pos.reset(
static_cast<Kate::TextCursor *
>(doc()->newMovingCursor(c.pos)));
3364 if (c.range.isValid()) {
3365 n.range.reset(newSecondarySelectionRange(c.range));
3366 n.anchor = c.range.start() == c.pos ? c.range.end() : c.range.start();
3368 m_secondaryCursors.push_back(std::move(n));
3377 auto range =
new Kate::TextRange(&doc()->buffer(), selRange, expandBehaviour);
3382 selAttr->setBackground(color);
3384 range->setZDepth(-999999.);
3385 range->setAttribute(selAttr);
3389bool KTextEditor::ViewPrivate::hasSelections()
const
3393 return std::any_of(m_secondaryCursors.cbegin(), m_secondaryCursors.cend(), [](
const SecondaryCursor &c) {
3394 return c.range && !c.range->isEmpty();
3398void KTextEditor::ViewPrivate::addSecondaryCursorDown()
3401 const auto &secondary = secondaryCursors();
3402 if (!secondary.empty()) {
3403 last = secondary.back().cursor();
3404 last = std::max(cursorPosition(), last);
3406 if (last.
line() >= doc()->lastLine()) {
3410 auto nextRange = m_viewInternal->nextLayout(last);
3411 if (!nextRange.isValid()) {
3414 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3415 if (!primaryCursorLineLayout.isValid()) {
3419 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3420 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3421 addSecondaryCursor(next);
3424void KTextEditor::ViewPrivate::addSecondaryCursorUp()
3427 const auto &secondary = secondaryCursors();
3428 if (!secondary.empty()) {
3429 last = secondary.front().cursor();
3430 last = std::min(cursorPosition(), last);
3432 if (last.
line() == 0) {
3435 auto nextRange = m_viewInternal->previousLayout(last);
3436 if (!nextRange.isValid()) {
3440 auto primaryCursorLineLayout = m_viewInternal->currentLayout(cursorPosition());
3441 if (!primaryCursorLineLayout.isValid()) {
3445 int x = renderer()->cursorToX(primaryCursorLineLayout, cursorPosition().column(), !wrapCursor());
3446 auto next = renderer()->xToCursor(nextRange, x, !wrapCursor());
3447 addSecondaryCursor(next);
3453 ret.
reserve(m_secondaryCursors.size() + 1);
3454 ret << cursorPosition();
3455 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3468 ret.
reserve(m_secondaryCursors.size() + 1);
3469 ret << selectionRange();
3470 std::transform(m_secondaryCursors.begin(), m_secondaryCursors.end(), std::back_inserter(ret), [](
const SecondaryCursor &c) {
3472 qWarning() <<
"selectionRanges(): Unexpected null selection range, please fix";
3473 return KTextEditor::Range::invalid();
3475 return c.range->toRange();
3482 if (isMulticursorNotAllowed()) {
3483 qWarning() <<
"setCursors failed: Multicursors not allowed because one of the following is true"
3484 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3489 clearSecondaryCursors();
3490 if (cursorPositions.
empty()) {
3494 const auto primary = cursorPositions.
front();
3498 setCursorPosition(primary);
3500 setSecondaryCursors(cursorPositions);
3505 if (isMulticursorNotAllowed()) {
3506 qWarning() <<
"setSelections failed: Multicursors not allowed because one of the following is true"
3507 <<
", blockSelection: " << blockSelection() <<
", overwriteMode: " << isOverwriteMode()
3512 clearSecondaryCursors();
3514 if (selectionRanges.
isEmpty()) {
3518 auto first = selectionRanges.
front();
3519 setCursorPosition(first.end());
3520 setSelection(first);
3522 if (selectionRanges.
size() == 1) {
3527 for (
auto it = selectionRanges.
begin() + 1; it != selectionRanges.
end(); ++it) {
3530 if (c == cursorPosition() || !r.
isValid() || r.
isEmpty() || !docRange.contains(r)) {
3536 n.range.reset(newSecondarySelectionRange(r));
3537 n.anchor = r.
start();
3538 m_secondaryCursors.push_back(std::move(n));
3540 m_viewInternal->mergeSelections();
3546void KTextEditor::ViewPrivate::sortCursors()
3548 std::sort(m_secondaryCursors.begin(), m_secondaryCursors.end());
3549 ensureUniqueCursors();
3552void KTextEditor::ViewPrivate::paintCursors()
3554 if (m_viewInternal->m_cursorTimer.isActive()) {
3558 renderer()->setDrawCaret(
true);
3560 m_viewInternal->paintCursor();
3563bool KTextEditor::ViewPrivate::isCompletionActive()
const
3565 return completionWidget()->isCompletionActive();
3570 if (!m_completionWidget) {
3574 return m_completionWidget;
3579 completionWidget()->startCompletion(word, model);
3582void KTextEditor::ViewPrivate::startCompletion(
const Range &word,
3584 KTextEditor::CodeCompletionModel::InvocationType invocationType)
3586 completionWidget()->startCompletion(word, models, invocationType);
3589void KTextEditor::ViewPrivate::abortCompletion()
3591 completionWidget()->abortCompletion();
3594void KTextEditor::ViewPrivate::forceCompletion()
3596 completionWidget()->execute();
3601 completionWidget()->registerCompletionModel(model);
3606 completionWidget()->unregisterCompletionModel(model);
3611 return completionWidget()->isCompletionModelRegistered(model);
3616 return completionWidget()->codeCompletionModels();
3619bool KTextEditor::ViewPrivate::isAutomaticInvocationEnabled()
const
3621 return !m_temporaryAutomaticInvocationDisabled && m_config->automaticCompletionInvocation();
3624void KTextEditor::ViewPrivate::setAutomaticInvocationEnabled(
bool enabled)
3626 config()->setValue(KateViewConfig::AutomaticCompletionInvocation, enabled);
3631 Q_EMIT completionExecuted(
this, position, model, index);
3634void KTextEditor::ViewPrivate::sendCompletionAborted()
3636 Q_EMIT completionAborted(
this);
3639void KTextEditor::ViewPrivate::paste(
const QString *textToPaste)
3641 const int cursorCount = m_secondaryCursors.size() + 1;
3643 if (cursorCount == multicursorClipboard.size() && !textToPaste) {
3644 if (doc()->multiPaste(
this, multicursorClipboard)) {
3647 }
else if (!textToPaste && cursorCount > 1) {
3653 for (
int i = 0; i < cursorCount; ++i) {
3658 if (doc()->multiPaste(
this, texts)) {
3663 m_temporaryAutomaticInvocationDisabled =
true;
3665 m_temporaryAutomaticInvocationDisabled =
false;
3670 return setCursorPositionInternal(position, 1,
true);
3675 return m_viewInternal->cursorPosition();
3680 return KTextEditor::Cursor(m_viewInternal->cursorPosition().line(), virtualCursorColumn());
3686 const QPoint pt = m_viewInternal->cursorToCoordinate(cursor,
true,
false);
3687 return pt ==
QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3693 return m_viewInternal->coordinatesToCursor(m_viewInternal->mapFromParent(coords),
false);
3696QPoint KTextEditor::ViewPrivate::cursorPositionCoordinates()
const
3699 const QPoint pt = m_viewInternal->cursorCoordinates(
false);
3700 return pt ==
QPoint(-1, -1) ? pt : m_viewInternal->mapToParent(pt);
3705 m_viewInternal->scrollPos(cursor,
false,
true,
false);
3708void KTextEditor::ViewPrivate::setHorizontalScrollPositionInternal(
int x)
3710 m_viewInternal->scrollColumns(x);
3715 return m_viewInternal->maxStartPos(
true);
3718int KTextEditor::ViewPrivate::firstDisplayedLineInternal(LineType lineType)
const
3720 if (lineType == RealLine) {
3721 return m_textFolding.visibleLineToLine(m_viewInternal->startLine());
3723 return m_viewInternal->startLine();
3727int KTextEditor::ViewPrivate::lastDisplayedLineInternal(LineType lineType)
const
3729 if (lineType == RealLine) {
3730 return m_textFolding.visibleLineToLine(m_viewInternal->endLine());
3732 return m_viewInternal->endLine();
3736QRect KTextEditor::ViewPrivate::textAreaRectInternal()
const
3738 const auto sourceRect = m_viewInternal->rect();
3739 const auto topLeft = m_viewInternal->mapTo(
this, sourceRect.topLeft());
3740 const auto bottomRight = m_viewInternal->mapTo(
this, sourceRect.bottomRight());
3741 return {topLeft, bottomRight};
3746 return setCursorPositionInternal(position, doc()->config()->tabWidth(),
true);
3749QScrollBar *KTextEditor::ViewPrivate::verticalScrollBar()
const
3751 return m_viewInternal->m_lineScroll;
3754QScrollBar *KTextEditor::ViewPrivate::horizontalScrollBar()
const
3756 return m_viewInternal->m_columnScroll;
3759bool KTextEditor::ViewPrivate::isLineRTL(
int line)
const
3763 int line = cursorPosition().line();
3765 const int count = doc()->
lines();
3766 for (
int i = 1; i < count; ++i) {
3774 int line = cursorPosition().line();
3775 for (; line >= 0; --line) {
3791 KateLineLayout *thisLine = m_viewInternal->cache()->line(pos.
line());
3792 return thisLine && thisLine->isValid() ? &thisLine->layout() :
nullptr;
3795void KTextEditor::ViewPrivate::indent()
3797 if (blockSelect && selection()) {
3798 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3801 doc()->indent(r, 1);
3807 doc()->indent(r, 1);
3809 for (
const auto &cursor : secondaryCursors()) {
3810 int line = cursor.cursor().
line();
3811 if (indentedLines.
contains(line)) {
3814 indentedLines.
insert(line);
3817 doc()->indent(r, 1);
3822void KTextEditor::ViewPrivate::unIndent()
3824 if (blockSelect && selection()) {
3825 for (
int line = selectionRange().
start().line(); line <= selectionRange().end().line(); line++) {
3828 doc()->indent(r, -1);
3834 doc()->indent(r, -1);
3836 for (
const auto &cursor : secondaryCursors()) {
3837 int line = cursor.cursor().
line();
3838 if (indentedLines.
contains(line)) {
3841 indentedLines.
insert(line);
3844 doc()->indent(r, -1);
3849void KTextEditor::ViewPrivate::cleanIndent()
3853 doc()->indent(r, 0);
3856void KTextEditor::ViewPrivate::formatIndent()
3859 const int line = cursorPosition().line();
3862 formatRange = selectionRange();
3865 doc()->align(
this, formatRange);
3869void KTextEditor::ViewPrivate::align()
3874void KTextEditor::ViewPrivate::alignOn()
3881 range = selectionRange();
3888 doc()->alignOn(range, pattern, this->blockSelection());
3891void KTextEditor::ViewPrivate::comment()
3894 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::Comment);
3898void KTextEditor::ViewPrivate::uncomment()
3900 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::UnComment);
3903void KTextEditor::ViewPrivate::toggleComment()
3906 doc()->comment(
this, cursorPosition().line(), cursorPosition().column(), DocumentPrivate::ToggleComment);
3910void KTextEditor::ViewPrivate::uppercase()
3912 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Uppercase);
3915void KTextEditor::ViewPrivate::killLine()
3917 std::vector<int> linesToRemove;
3918 if (m_selection.isEmpty()) {
3920 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3921 for (
const auto &c : m_secondaryCursors) {
3922 linesToRemove.push_back(c.pos->
line());
3925 linesToRemove.push_back(cursorPosition().line());
3927 linesToRemove.reserve(m_secondaryCursors.size() + 1);
3928 for (
const auto &c : m_secondaryCursors) {
3929 const auto &range = c.range;
3933 for (
int line = range->
end().
line(); line >= range->
start().
line(); line--) {
3934 linesToRemove.push_back(line);
3939 for (
int line = m_selection.end().line(), endLine = m_selection.start().line(); line >= endLine; line--) {
3940 linesToRemove.push_back(line);
3944 std::sort(linesToRemove.begin(), linesToRemove.end(), std::greater{});
3945 linesToRemove.erase(std::unique(linesToRemove.begin(), linesToRemove.end()), linesToRemove.end());
3950 clearSecondarySelections();
3951 std::for_each(linesToRemove.begin(), linesToRemove.end(), [
this](
int line) {
3952 doc()->removeLine(line);
3956 ensureUniqueCursors();
3959void KTextEditor::ViewPrivate::lowercase()
3961 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
3964void KTextEditor::ViewPrivate::capitalize()
3967 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Lowercase);
3968 doc()->
transform(
this, cursorPosition(), KTextEditor::DocumentPrivate::Capitalize);
3972void KTextEditor::ViewPrivate::keyReturn()
3974 doc()->newLine(
this);
3975 m_viewInternal->iconBorder()->updateForCursorLineChange();
3976 m_viewInternal->updateView();
3979void KTextEditor::ViewPrivate::smartNewline()
3982 const int ln = cursor.
line();
3997 m_viewInternal->updateView();
4000void KTextEditor::ViewPrivate::noIndentNewline()
4002 doc()->newLine(
this, KTextEditor::DocumentPrivate::NoIndent);
4003 m_viewInternal->iconBorder()->updateForCursorLineChange();
4004 m_viewInternal->updateView();
4007void KTextEditor::ViewPrivate::newLineAbove()
4009 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Above);
4010 m_viewInternal->iconBorder()->updateForCursorLineChange();
4011 m_viewInternal->updateView();
4014void KTextEditor::ViewPrivate::newLineBelow()
4016 doc()->newLine(
this, KTextEditor::DocumentPrivate::Indent, KTextEditor::DocumentPrivate::Below);
4017 m_viewInternal->iconBorder()->updateForCursorLineChange();
4018 m_viewInternal->updateView();
4021void KTextEditor::ViewPrivate::backspace()
4024 doc()->backspace(
this);
4027void KTextEditor::ViewPrivate::insertTab()
4029 doc()->insertTab(
this, cursorPosition());
4032void KTextEditor::ViewPrivate::deleteWordLeft()
4035 m_viewInternal->wordPrev(
true);
4037 removeSelectedText();
4040 ensureUniqueCursors();
4042 m_viewInternal->tagRange(selection,
true);
4043 m_viewInternal->updateDirty();
4046void KTextEditor::ViewPrivate::keyDelete()
4054 selection = {selection.
start(),
end};
4055 doc()->removeText(selection, blockSelect);
4062 if (removeSelectedText()) {
4066 for (
const auto &c : m_secondaryCursors) {
4068 doc()->removeText(c.range->toRange());
4070 doc()->del(
this, c.cursor());
4075 doc()->del(
this, cursorPosition());
4077 ensureUniqueCursors();
4080void KTextEditor::ViewPrivate::deleteWordRight()
4083 m_viewInternal->wordNext(
true);
4085 removeSelectedText();
4088 ensureUniqueCursors();
4090 m_viewInternal->tagRange(selection,
true);
4091 m_viewInternal->updateDirty();
4094void KTextEditor::ViewPrivate::transpose()
4097 for (
const auto &c : m_secondaryCursors) {
4098 doc()->transpose(c.cursor());
4100 doc()->transpose(cursorPosition());
4104void KTextEditor::ViewPrivate::transposeWord()
4113 for (
const QChar &character : word) {
4114 if (character.isLetterOrNumber()) {
4121 if (wordIsInvalid(doc()->text(firstWord))) {
4125 setCursorPosition(firstWord.
end());
4130 setCursorPosition(firstWord.
start());
4132 curPos = cursorPosition();
4135 setCursorPosition(originalCurPos);
4140 if (wordIsInvalid(doc()->wordAt(curPos))) {
4141 setCursorPosition(originalCurPos);
4146 doc()->swapTextRanges(firstWord, secondWord);
4150 const int offsetFromWordEnd = firstWord.
end().
column() - originalCurPos.
column();
4154void KTextEditor::ViewPrivate::cursorLeft()
4156 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4157 if (isLineRTL(cursorPosition().line())) {
4158 m_viewInternal->updateCursor(selectionRange().
end());
4161 m_viewInternal->updateCursor(selectionRange().
start());
4165 for (
const auto &c : m_secondaryCursors) {
4169 const bool rtl = isLineRTL(c.cursor().
line());
4172 clearSecondarySelections();
4174 if (isLineRTL(cursorPosition().line())) {
4175 m_viewInternal->cursorNextChar(m_markedSelection);
4177 m_viewInternal->cursorPrevChar(m_markedSelection);
4182void KTextEditor::ViewPrivate::shiftCursorLeft()
4184 if (isLineRTL(cursorPosition().line())) {
4185 m_viewInternal->cursorNextChar(
true);
4187 m_viewInternal->cursorPrevChar(
true);
4191void KTextEditor::ViewPrivate::cursorRight()
4193 if (selection() && !config()->persistentSelection() && !m_markedSelection) {
4194 if (isLineRTL(cursorPosition().line())) {
4195 m_viewInternal->updateCursor(selectionRange().
start());
4198 m_viewInternal->updateCursor(selectionRange().
end());
4202 for (
const auto &c : m_secondaryCursors) {
4209 clearSecondarySelections();
4211 if (isLineRTL(cursorPosition().line())) {
4212 m_viewInternal->cursorPrevChar(m_markedSelection);
4214 m_viewInternal->cursorNextChar(m_markedSelection);
4219void KTextEditor::ViewPrivate::shiftCursorRight()
4221 if (isLineRTL(cursorPosition().line())) {
4222 m_viewInternal->cursorPrevChar(
true);
4224 m_viewInternal->cursorNextChar(
true);
4228void KTextEditor::ViewPrivate::wordLeft()
4230 if (isLineRTL(cursorPosition().line())) {
4231 m_viewInternal->wordNext(m_markedSelection);
4233 m_viewInternal->wordPrev(m_markedSelection);
4237void KTextEditor::ViewPrivate::shiftWordLeft()
4239 if (isLineRTL(cursorPosition().line())) {
4240 m_viewInternal->wordNext(
true);
4242 m_viewInternal->wordPrev(
true);
4246void KTextEditor::ViewPrivate::wordRight()
4248 if (isLineRTL(cursorPosition().line())) {
4249 m_viewInternal->wordPrev(m_markedSelection);
4251 m_viewInternal->wordNext(m_markedSelection);
4255void KTextEditor::ViewPrivate::shiftWordRight()
4257 if (isLineRTL(cursorPosition().line())) {
4258 m_viewInternal->wordPrev(
true);
4260 m_viewInternal->wordNext(
true);
4264void KTextEditor::ViewPrivate::markSelection()
4266 if (m_markedSelection && selection()) {
4268 clearSecondarySelections();
4270 m_markedSelection = !m_markedSelection;
4274void KTextEditor::ViewPrivate::home()
4276 m_viewInternal->home(m_markedSelection);
4279void KTextEditor::ViewPrivate::shiftHome()
4281 m_viewInternal->home(
true);
4284void KTextEditor::ViewPrivate::end()
4286 m_viewInternal->end(m_markedSelection);
4289void KTextEditor::ViewPrivate::shiftEnd()
4291 m_viewInternal->end(
true);
4294void KTextEditor::ViewPrivate::up()
4296 m_viewInternal->cursorUp(m_markedSelection);
4299void KTextEditor::ViewPrivate::shiftUp()
4301 m_viewInternal->cursorUp(
true);
4304void KTextEditor::ViewPrivate::down()
4306 m_viewInternal->cursorDown(m_markedSelection);
4309void KTextEditor::ViewPrivate::shiftDown()
4311 m_viewInternal->cursorDown(
true);
4314void KTextEditor::ViewPrivate::scrollUp()
4316 m_viewInternal->scrollUp();
4319void KTextEditor::ViewPrivate::scrollDown()
4321 m_viewInternal->scrollDown();
4324void KTextEditor::ViewPrivate::topOfView()
4326 m_viewInternal->topOfView();
4329void KTextEditor::ViewPrivate::shiftTopOfView()
4331 m_viewInternal->topOfView(
true);
4334void KTextEditor::ViewPrivate::bottomOfView()
4336 m_viewInternal->bottomOfView();
4339void KTextEditor::ViewPrivate::shiftBottomOfView()
4341 m_viewInternal->bottomOfView(
true);
4344void KTextEditor::ViewPrivate::pageUp()
4346 m_viewInternal->pageUp(m_markedSelection);
4349void KTextEditor::ViewPrivate::shiftPageUp()
4351 m_viewInternal->pageUp(
true);
4354void KTextEditor::ViewPrivate::pageDown()
4356 m_viewInternal->pageDown(m_markedSelection);
4359void KTextEditor::ViewPrivate::shiftPageDown()
4361 m_viewInternal->pageDown(
true);
4364void KTextEditor::ViewPrivate::top()
4366 m_viewInternal->top_home(m_markedSelection);
4369void KTextEditor::ViewPrivate::shiftTop()
4371 m_viewInternal->top_home(
true);
4374void KTextEditor::ViewPrivate::bottom()
4376 m_viewInternal->bottom_end(m_markedSelection);
4379void KTextEditor::ViewPrivate::shiftBottom()
4381 m_viewInternal->bottom_end(
true);
4384void KTextEditor::ViewPrivate::toMatchingBracket()
4386 m_viewInternal->cursorToMatchingBracket();
4389void KTextEditor::ViewPrivate::shiftToMatchingBracket()
4391 m_viewInternal->cursorToMatchingBracket(
true);
4394void KTextEditor::ViewPrivate::toPrevModifiedLine()
4396 const int startLine = cursorPosition().line() - 1;
4400 m_viewInternal->updateSelection(c,
false);
4401 m_viewInternal->updateCursor(c);
4405void KTextEditor::ViewPrivate::toNextModifiedLine()
4407 const int startLine = cursorPosition().line() + 1;
4411 m_viewInternal->updateSelection(c,
false);
4412 m_viewInternal->updateCursor(c);
4426void KTextEditor::ViewPrivate::setContextMenu(
QMenu *menu)
4428 if (m_contextMenu) {
4429 disconnect(m_contextMenu.data(), &
QMenu::aboutToShow,
this, &KTextEditor::ViewPrivate::aboutToShowContextMenu);
4430 disconnect(m_contextMenu.data(), &
QMenu::aboutToHide,
this, &KTextEditor::ViewPrivate::aboutToHideContextMenu);
4432 m_contextMenu = menu;
4433 m_userContextMenuSet =
true;
4435 if (m_contextMenu) {
4441QMenu *KTextEditor::ViewPrivate::contextMenu()
const
4443 if (m_userContextMenuSet) {
4444 return m_contextMenu;
4446 KXMLGUIClient *client =
const_cast<KTextEditor::ViewPrivate *
>(
this);
4454 for (
QWidget *w : menuContainers) {
4455 if (w->objectName() ==
QLatin1String(
"ktexteditor_popup")) {
4475QMenu *KTextEditor::ViewPrivate::defaultContextMenu(
QMenu *menu)
const
4478 menu =
new QMenu(
const_cast<KTextEditor::ViewPrivate *
>(
this));
4492 if (m_pasteSelection) {
4501 QAction *editing = actionCollection()->action(QStringLiteral(
"tools_scripts_Editing"));
4505 if (
QAction *spellingSuggestions = actionCollection()->action(QStringLiteral(
"spelling_suggestions"))) {
4509 if (
QAction *bookmark = actionCollection()->action(QStringLiteral(
"bookmarks"))) {
4517void KTextEditor::ViewPrivate::aboutToShowContextMenu()
4519 QMenu *menu = qobject_cast<QMenu *>(sender());
4522 Q_EMIT contextMenuAboutToShow(
this, menu);
4526void KTextEditor::ViewPrivate::aboutToHideContextMenu()
4528 m_spellingMenu->cleanUpAfterShown();
4532QStringList KTextEditor::ViewPrivate::configKeys()
const
4534 static const QStringList keys = {QStringLiteral(
"icon-bar"),
4535 QStringLiteral(
"line-numbers"),
4536 QStringLiteral(
"dynamic-word-wrap"),
4537 QStringLiteral(
"background-color"),
4538 QStringLiteral(
"selection-color"),
4539 QStringLiteral(
"search-highlight-color"),
4540 QStringLiteral(
"replace-highlight-color"),
4541 QStringLiteral(
"default-mark-type"),
4542 QStringLiteral(
"allow-mark-menu"),
4543 QStringLiteral(
"folding-bar"),
4544 QStringLiteral(
"folding-preview"),
4545 QStringLiteral(
"icon-border-color"),
4546 QStringLiteral(
"folding-marker-color"),
4547 QStringLiteral(
"line-number-color"),
4548 QStringLiteral(
"current-line-number-color"),
4549 QStringLiteral(
"modification-markers"),
4550 QStringLiteral(
"keyword-completion"),
4551 QStringLiteral(
"word-count"),
4552 QStringLiteral(
"line-count"),
4553 QStringLiteral(
"scrollbar-minimap"),
4554 QStringLiteral(
"scrollbar-preview"),
4555 QStringLiteral(
"font"),
4556 QStringLiteral(
"theme")};
4563 return config()->iconBar();
4565 return config()->lineNumbers();
4567 return config()->dynWordWrap();
4569 return rendererConfig()->backgroundColor();
4571 return rendererConfig()->selectionColor();
4572 }
else if (key ==
QLatin1String(
"search-highlight-color")) {
4573 return rendererConfig()->searchHighlightColor();
4574 }
else if (key ==
QLatin1String(
"replace-highlight-color")) {
4575 return rendererConfig()->replaceHighlightColor();
4577 return config()->defaultMarkType();
4579 return config()->allowMarkMenu();
4581 return config()->foldingBar();
4583 return config()->foldingPreview();
4585 return rendererConfig()->iconBarColor();
4587 return rendererConfig()->foldingColor();
4589 return rendererConfig()->lineNumberColor();
4590 }
else if (key ==
QLatin1String(
"current-line-number-color")) {
4591 return rendererConfig()->currentLineNumberColor();
4593 return config()->lineModification();
4595 return config()->keywordCompletion();
4597 return config()->showWordCount();
4599 return config()->showLineCount();
4601 return config()->scrollBarMiniMap();
4603 return config()->scrollBarPreview();
4605 return rendererConfig()->baseFont();
4607 return rendererConfig()->schema();
4614void KTextEditor::ViewPrivate::setConfigValue(
const QString &key,
const QVariant &value)
4617 if (config()->setValue(key, value)) {
4620 }
else if (rendererConfig()->setValue(key, value)) {
4627 rendererConfig()->setBackgroundColor(value.
value<
QColor>());
4629 rendererConfig()->setSelectionColor(value.
value<
QColor>());
4630 }
else if (key ==
QLatin1String(
"search-highlight-color")) {
4631 rendererConfig()->setSearchHighlightColor(value.
value<
QColor>());
4632 }
else if (key ==
QLatin1String(
"replace-highlight-color")) {
4633 rendererConfig()->setReplaceHighlightColor(value.
value<
QColor>());
4635 rendererConfig()->setIconBarColor(value.
value<
QColor>());
4637 rendererConfig()->setFoldingColor(value.
value<
QColor>());
4639 rendererConfig()->setLineNumberColor(value.
value<
QColor>());
4640 }
else if (key ==
QLatin1String(
"current-line-number-color")) {
4641 rendererConfig()->setCurrentLineNumberColor(value.
value<
QColor>());
4648 config()->setDynWordWrap(value.
toBool());
4650 config()->setShowWordCount(value.
toBool());
4652 config()->setShowLineCount(value.
toBool());
4655 rendererConfig()->setFont(value.
value<
QFont>());
4657 rendererConfig()->setSchema(value.
toString());
4664void KTextEditor::ViewPrivate::userInvokedCompletion()
4666 completionWidget()->userInvokedCompletion();
4669KateViewBar *KTextEditor::ViewPrivate::bottomViewBar()
const
4671 return m_bottomViewBar;
4674KateGotoBar *KTextEditor::ViewPrivate::gotoBar()
4677 m_gotoBar =
new KateGotoBar(
this);
4678 bottomViewBar()->addBarWidget(m_gotoBar);
4684KateDictionaryBar *KTextEditor::ViewPrivate::dictionaryBar()
4686 if (!m_dictionaryBar) {
4687 m_dictionaryBar =
new KateDictionaryBar(
this);
4688 bottomViewBar()->addBarWidget(m_dictionaryBar);
4691 return m_dictionaryBar;
4697 m_annotationModel = model;
4698 m_viewInternal->m_leftBorder->annotationModelChanged(oldmodel, m_annotationModel);
4703 return m_annotationModel;
4706void KTextEditor::ViewPrivate::setAnnotationBorderVisible(
bool visible)
4708 m_viewInternal->m_leftBorder->setAnnotationBorderOn(visible);
4711bool KTextEditor::ViewPrivate::isAnnotationBorderVisible()
const
4713 return m_viewInternal->m_leftBorder->annotationBorderOn();
4718 return m_viewInternal->m_leftBorder->annotationItemDelegate();
4723 m_viewInternal->m_leftBorder->setAnnotationItemDelegate(delegate);
4726bool KTextEditor::ViewPrivate::uniformAnnotationItemSizes()
const
4728 return m_viewInternal->m_leftBorder->uniformAnnotationItemSizes();
4731void KTextEditor::ViewPrivate::setAnnotationUniformItemSizes(
bool enable)
4733 m_viewInternal->m_leftBorder->setAnnotationUniformItemSizes(enable);
4739 if (!m_viewInternal->endPos().isValid()) {
4740 m_viewInternal->updateView();
4742 return KTextEditor::Range(m_viewInternal->toRealCursor(m_viewInternal->startPos()), m_viewInternal->toRealCursor(m_viewInternal->endPos()));
4745bool KTextEditor::ViewPrivate::event(
QEvent *e)
4747 switch (e->
type()) {
4756void KTextEditor::ViewPrivate::toggleOnTheFlySpellCheck(
bool b)
4758 doc()->onTheFlySpellCheckingEnabled(b);
4761void KTextEditor::ViewPrivate::reflectOnTheFlySpellCheckStatus(
bool enabled)
4763 m_spellingMenu->setVisible(enabled);
4764 m_toggleOnTheFlySpellCheck->setChecked(enabled);
4767KateSpellingMenu *KTextEditor::ViewPrivate::spellingMenu()
4769 return m_spellingMenu;
4774#ifdef VIEW_RANGE_DEBUG
4776 qCDebug(LOG_KTE) <<
"trigger attribute changed in line range " << lineRange <<
"needsRepaint" << needsRepaint;
4780 m_rangesCaretIn.remove(deleteRange);
4781 m_rangesMouseIn.remove(deleteRange);
4785 if (needsRepaint && lineRange.
isValid()) {
4786 if (m_lineToUpdateRange.isValid()) {
4787 m_lineToUpdateRange.expandToRange(lineRange);
4789 m_lineToUpdateRange = lineRange;
4794 if (!m_delayedUpdateTimer.isActive()) {
4795 m_delayedUpdateTimer.start();
4799void KTextEditor::ViewPrivate::slotDelayedUpdateOfView()
4801#ifdef VIEW_RANGE_DEBUG
4803 qCDebug(LOG_KTE) <<
"delayed attribute changed in line range" << m_lineToUpdateRange;
4810 if (m_lineToUpdateRange.isValid()) {
4811 tagLines(m_lineToUpdateRange,
true);
4835 if (currentCursor.
isValid() && currentCursor.
line() < doc()->buffer().lines()) {
4842 auto attribute = range->attribute();
4843 if ((!attribute || !attribute->dynamicAttribute(activationType)) && !range->feedback()) {
4849 : (currentCursor <= range->toRange().
start())) {
4854 : (range->toRange().
end() < currentCursor)) {
4859 auto it = validRanges.
find(range);
4860 if (it != validRanges.
end()) {
4862 newRangesIn.
insert(range);
4863 validRanges.
erase(it);
4868 newRangesIn.
insert(range);
4870 if (attribute && attribute->dynamicAttribute(activationType)) {
4871 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4875 if (range->feedback()) {
4877 range->feedback()->mouseEnteredRange(range,
this);
4879 range->feedback()->caretEnteredRange(range,
this);
4880 Q_EMIT caretChangedRange(
this);
4884#ifdef VIEW_RANGE_DEBUG
4886 qCDebug(LOG_KTE) <<
"activated new range" << range <<
"by" << activationType;
4894 if (range->toRange().
isValid() && range->attribute() && range->attribute()->dynamicAttribute(activationType)) {
4895 notifyAboutRangeChange(range->
toLineRange(),
true,
nullptr);
4899 if (range->feedback()) {
4901 range->feedback()->mouseExitedRange(range,
this);
4903 range->feedback()->caretExitedRange(range,
this);
4904 Q_EMIT caretChangedRange(
this);
4910 oldSet = newRangesIn;
4916 auto messageWidget = m_messageWidgets[message->
position()];
4917 if (!messageWidget) {
4920 m_messageWidgets[message->
position()] = messageWidget;
4921 m_notificationLayout->addWidget(messageWidget, message->
position());
4925 messageWidget->postMessage(message, std::move(actions));
4933void KTextEditor::ViewPrivate::saveFoldingState()
4935 m_savedFoldingState = m_textFolding.exportFoldingRanges();
4938void KTextEditor::ViewPrivate::clearFoldingState()
4940 m_savedFoldingState = {};
4943void KTextEditor::ViewPrivate::applyFoldingState()
4945 m_textFolding.importFoldingRanges(m_savedFoldingState);
4949void KTextEditor::ViewPrivate::exportHtmlToFile(
const QString &file)
4951 KateExporter(
this).exportToFile(file);
4954void KTextEditor::ViewPrivate::exportHtmlToClipboard()
4956 KateExporter(
this).exportToClipboard();
4959void KTextEditor::ViewPrivate::exportHtmlToFile()
4963 KateExporter(
this).exportToFile(file);
4967void KTextEditor::ViewPrivate::clearHighlights()
4969 m_rangesForHighlights.clear();
4970 m_currentTextForHighlights.clear();
4973void KTextEditor::ViewPrivate::selectionChangedForHighlights()
4977 if (!m_secondaryCursors.empty()) {
4978 for (
const auto &cursor : m_secondaryCursors) {
4986 if (selection() && selectionRange().onSingleLine()) {
4987 text = selectionText();
4988 if (text == m_currentTextForHighlights) {
4995 m_rangesForHighlights.
clear();
5003 m_currentTextForHighlights = text;
5007void KTextEditor::ViewPrivate::createHighlights()
5010 if (m_currentTextForHighlights.isEmpty()) {
5015 m_rangesForHighlights.clear();
5021 QColor fgColor = defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle::Normal)->foreground().color();
5022 QColor bgColor = rendererConfig()->searchHighlightColor();
5023 attr->setForeground(fgColor);
5024 attr->setBackground(bgColor);
5046 if (matches.
first().isValid()) {
5047 if (matches.
first() != selectionRange()) {
5048 std::unique_ptr<KTextEditor::MovingRange> mr(doc()->newMovingRange(matches.
first()));
5049 mr->setZDepth(-90000.0);
5050 mr->setAttribute(attr);
5052 mr->setAttributeOnlyForViews(
true);
5053 m_rangesForHighlights.push_back(std::move(mr));
5057 }
while (matches.
first().isValid());
5060KateAbstractInputMode *KTextEditor::ViewPrivate::currentInputMode()
const
5062 return m_viewInternal->m_currentInputMode;
5065void KTextEditor::ViewPrivate::toggleInputMode()
5067 if (
QAction *a = qobject_cast<QAction *>(sender())) {
5072void KTextEditor::ViewPrivate::cycleInputMode()
5074 InputMode current = currentInputMode()->viewInputMode();
5080bool KTextEditor::ViewPrivate::print()
5082 return KatePrinter::print(
this);
5085void KTextEditor::ViewPrivate::printPreview()
5087 KatePrinter::printPreview(
this);
5095 if (std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider) == m_inlineNoteProviders.cend()) {
5096 m_inlineNoteProviders.push_back(provider);
5107 auto it = std::find(m_inlineNoteProviders.cbegin(), m_inlineNoteProviders.cend(), provider);
5108 if (it != m_inlineNoteProviders.cend()) {
5109 m_inlineNoteProviders.erase(it);
5122 for (
int column : columns) {
5123 const bool underMouse = Cursor(line, column) == m_viewInternal->m_activeInlineNote.m_position;
5125 {provider,
this, {line, column}, index, underMouse, m_viewInternal->renderer()->currentFont(), m_viewInternal->renderer()->lineHeight()};
5126 allInlineNotes.
append(note);
5130 return allInlineNotes;
5135 return m_viewInternal->inlineNoteRect(note);
5138void KTextEditor::ViewPrivate::inlineNotesReset()
5140 m_viewInternal->m_activeInlineNote = {};
5144void KTextEditor::ViewPrivate::inlineNotesLineChanged(
int line)
5146 if (line == m_viewInternal->m_activeInlineNote.m_position.line()) {
5147 m_viewInternal->m_activeInlineNote = {};
5149 tagLines({line, line},
true);
5156 KateRendererConfig *renderConfig =
const_cast<KTextEditor::ViewPrivate *
>(
this)->rendererConfig();
5162 style->setBackground(
QBrush(renderConfig->backgroundColor()));
5171 if (line < 0 || line >= doc()->lines()) {
5177 for (qsizetype i = 0; i < intAttrs.size(); ++i) {
5178 if (intAttrs[i].length > 0 && intAttrs[i].attributeValue > 0) {
5179 attribs <<
KTextEditor::AttributeBlock(intAttrs.at(i).offset, intAttrs.at(i).length, renderer()->attribute(intAttrs.at(i).attributeValue));
5186void KTextEditor::ViewPrivate::copyFileLocation()
const
5192#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.
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.
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.
void displayRangeChanged(KTextEditor::View *view)
This signal is emitted whenever the displayed range changes.
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 bool focusOut(int ms=-1)
Q_SCRIPTABLE Q_NOREPLY void start()
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)
KGUIADDONS_EXPORT QWindow * window(QObject *job)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
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 > & paste()
const QList< QKeySequence > & end()
const QList< QKeySequence > & copy()
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 > & selectAll()
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)
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)
bool contains(const QSet< T > &other) const const
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
qsizetype size() const const