KTextEditor
katetemplatehandler.cpp
47 std::unique_ptr<MovingRange> selection(doc()->newMovingRange(m_view->selectionRange(), MovingRange::DoNotExpand));
52 connect(doc(), &KTextEditor::DocumentPrivate::textInsertedRange, this, &KateTemplateHandler::slotTemplateInserted);
70 const bool have_editable_field = std::any_of(m_fields.constBegin(), m_fields.constEnd(), [](const TemplateField &field) {
83 connect(doc(), &KTextEditor::Document::viewCreated, this, &KateTemplateHandler::slotViewCreated);
84 connect(doc(), &KTextEditor::DocumentPrivate::textInsertedRange, this, [this](KTextEditor::Document *doc, KTextEditor::Range range) {
87 connect(doc(), &KTextEditor::DocumentPrivate::textRemoved, this, [this](KTextEditor::Document *doc, KTextEditor::Range range, const QString &) {
106 std::sort(m_fields.begin(), m_fields.end(), [](const TemplateField &l, const TemplateField &r) {
168 if ((!field.removed && kind == TemplateField::Editable) || kind == TemplateField::FinalCursorPosition) {
203 m_wholeTemplateRange.reset(doc()->newMovingRange(range, MovingRange::ExpandLeft | MovingRange::ExpandRight));
205 disconnect(doc(), &KTextEditor::DocumentPrivate::textInsertedRange, this, &KateTemplateHandler::slotTemplateInserted);
241 if (keyEvent->key() == Qt::Key_Escape || (keyEvent->key() == Qt::Key_Return && keyEvent->modifiers() & Qt::AltModifier)) {
281 static const QRegularExpression field(QStringLiteral("\\\\?\\${([^}]+)}"), QRegularExpression::UseUnicodePropertiesOption);
283 static const QRegularExpression defaultField(QStringLiteral("\\w+=([^\\}]*)"), QRegularExpression::UseUnicodePropertiesOption);
292 return Cursor(start.line(), rel_lineno == 0 ? start.column() : 0) + Cursor(rel_lineno, offset - left.lastIndexOf(nl) - 1);
298 return doc()->newMovingRange({matchStart, matchStart + Cursor(0, match.capturedLength(0))}, MovingRange::ExpandLeft | MovingRange::ExpandRight);
323 f.identifier = QStringView(contents).left(contents.indexOf(QLatin1Char('='))).trimmed().toString();
332 if (other.kind == TemplateField::Editable && !(f == other) && other.identifier == f.identifier) {
351 editableAttribute->setDynamicAttribute(Attribute::ActivateCaretIn, getAttribute(config->templateFocusedEditablePlaceholderColor(), 255));
359 field.range->setAttribute(field.kind == TemplateField::Editable ? editableAttribute : notEditableAttribute);
391 ifDebug(qCDebug(LOG_KTE) << "update field:" << field.range->toRange();) updateDependentFields(doc(), field.range->toRange());
397const KateTemplateHandler::TemplateField KateTemplateHandler::fieldForRange(KTextEditor::Range range) const
400 if (!field.removed && (field.range->contains(range.start()) || field.range->end() == range.start())) {
403 if (field.kind == TemplateField::FinalCursorPosition && range.end() == field.range->end().toCursor()) {
410void KateTemplateHandler::updateDependentFields(Document *document, Range range, bool textRemoved)
420 bool at_end = m_wholeTemplateRange->toRange().end() == range.end() || m_wholeTemplateRange->toRange().end() == range.start();
445 if (changedField.kind == TemplateField::FinalCursorPosition && doc()->text(changedField.range->toRange()).isEmpty()) {
492 if (field->kind == TemplateField::Mirror && changedField.kind == TemplateField::Editable && field->identifier == changedField.identifier) {
Backend of KTextEditor::Document related public KTextEditor interfaces.
Definition katedocument.h:68
KTextEditor::MovingRange * newMovingRange(KTextEditor::Range range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty) override
Create a new moving range for this document.
Definition katedocument.cpp:5851
QString text(KTextEditor::Range range, bool blockwise=false) const override
Get the document content within the given range.
Definition katedocument.cpp:442
void textRemoved(KTextEditor::Document *document, KTextEditor::Range range, const QString &oldText)
The document emits this signal whenever range was removed, i.e.
void textInsertedRange(KTextEditor::Document *document, KTextEditor::Range range)
The document emits this signal whenever text was inserted.
QList< KTextEditor::View * > views() const override
Returns the views pre-casted to KTextEditor::Views.
Definition katedocument.h:127
void viewCreated(KTextEditor::Document *document, KTextEditor::View *view)
This signal is emitted whenever the document creates a new view.
void aboutToReload(KTextEditor::Document *document)
Warn anyone listening that the current document is about to reload.
@ DoNotExpand
Don't expand to encapsulate new characters in either direction. This is the default.
Definition movingrange.h:142
@ ExpandRight
Expand to encapsulate new characters to the right of the range.
Definition movingrange.h:146
@ ExpandLeft
Expand to encapsulate new characters to the left of the range.
Definition movingrange.h:144
An object representing a section of text, from one Cursor to another.
Definition include/ktexteditor/range.h:49
constexpr Cursor end() const noexcept
Get the end position of this range.
Definition include/ktexteditor/range.h:163
constexpr Cursor start() const noexcept
Get the start position of this range.
Definition include/ktexteditor/range.h:153
constexpr bool isEmpty() const noexcept
Returns true if this range contains no characters, ie.
Definition include/ktexteditor/range.h:301
constexpr bool onSingleLine() const noexcept
Check whether this range is wholly contained within one line, ie.
Definition include/ktexteditor/range.h:268
constexpr bool contains(Range range) const noexcept
Check whether the this range wholly encompasses range.
Definition include/ktexteditor/range.h:323
KateScript objects represent a script that can be executed and inspected.
Definition katescript.h:107
bool setView(KTextEditor::ViewPrivate *view)
set view for this script for the execution will trigger load!
Definition katescript.cpp:224
QJSValue evaluate(const QString &program, const FieldMap &env=FieldMap())
Execute a piece of code.
Definition katescript.cpp:184
Inserts a template and offers advanced snippet features, like navigation and mirroring.
Definition katetemplatehandler.h:54
bool eventFilter(QObject *object, QEvent *event) override
Provide keyboard interaction for the template handler.
Definition katetemplatehandler.cpp:225
KateTemplateHandler(KTextEditor::ViewPrivate *view, KTextEditor::Cursor position, const QString &templateString, const QString &script, KateUndoManager *undoManager)
Setup the template handler, insert the template string.
Definition katetemplatehandler.cpp:30
void setAllowComplexMerge(bool allow)
Allows or disallows merging of "complex" undo groups.
Definition kateundomanager.cpp:569
Q_SCRIPTABLE Q_NOREPLY void start()
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
const QList< QKeySequence > & next()
const QList< QKeySequence > & end()
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition katetextblock.h:18
void setAlpha(int alpha)
KeyPress
QString toString() const const
iterator begin()
const_iterator constBegin() const const
const_iterator constEnd() const const
iterator end()
void prepend(parameter_type value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool disconnect(const QMetaObject::Connection &connection)
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void installEventFilter(QObject *filterObj)
UseUnicodePropertiesOption
QString & append(QChar ch)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QStringView left(qsizetype length) const const
QString toString() const const
QStringView trimmed() const const
Key_Tab
AltModifier
QTextStream & left(QTextStream &stream)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.