Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Make character properties edit the word when there's no selection.

Wolthera van Hövell tot Westerflier2a0a812ad9fb
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cpp
index d94b0cd2be..24a9a3508a 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp
+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp
@@ -598,10 +598,8 @@ QList<KoSvgTextProperties> SvgTextCursor::propertiesForRange() const
if (!d->shape) return QList<KoSvgTextProperties>();
int start = -1;
int end = -1;
- //if (d->pos != d->anchor) {
- start = qMin(d->pos, d->anchor);
- end = qMax(d->pos, d->anchor);
- //}
+ start = qMin(d->pos, d->anchor);
+ end = qMax(d->pos, d->anchor);
return d->shape->propertiesForRange(start, end);
}
@@ -611,7 +609,7 @@ QList<KoSvgTextProperties> SvgTextCursor::propertiesForShape() const
return {d->shape->propertiesForRange(-1, -1)};
}
-void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties, bool paragraphOnly)
+void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties, bool paragraphOnly, bool selectWord)
{
if (d->shape) {
int start = -1;
@@ -620,6 +618,11 @@ void SvgTextCursor::mergePropertiesIntoSelection(const KoSvgTextProperties props
start = d->pos;
end = d->anchor;
}
+ if (selectWord && d->pos == d->anchor) {
+ const int finalPos = d->shape->posForIndex(d->shape->plainText().size());
+ start = qBound(0, moveModeResult(MoveWordStart, d->pos, d->visualNavigation), finalPos);
+ end = qBound(0, moveModeResult(MoveWordEnd, d->pos, d->visualNavigation), finalPos);
+ }
KUndo2Command *cmd = new SvgTextMergePropertiesRangeCommand(d->shape, props, start, end, removeProperties);
addCommandToUndoAdapter(cmd);
}
@@ -1225,7 +1228,7 @@ void SvgTextCursor::canvasResourceChanged(int key, const QVariant &value)
}
}
if (!props.isEmpty()) {
- mergePropertiesIntoSelection(props, QSet<KoSvgTextProperties::PropertyId>(), false);
+ mergePropertiesIntoSelection(props, QSet<KoSvgTextProperties::PropertyId>(), !hasSelection());
}
}
@@ -1793,7 +1796,7 @@ void SvgTextCursor::addCommandToUndoAdapter(KUndo2Command *cmd)
}
}
-int SvgTextCursor::moveModeResult(SvgTextCursor::MoveMode &mode, int &pos, bool visual) const
+int SvgTextCursor::moveModeResult(const SvgTextCursor::MoveMode mode, int &pos, bool visual) const
{
int newPos = pos;
switch (mode) {
@@ -1989,7 +1992,7 @@ void SvgTextCursorPropertyInterface::setPropertiesOnSelected(KoSvgTextProperties
void SvgTextCursorPropertyInterface::setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties)
{
- d->parent->mergePropertiesIntoSelection(properties, removeProperties, false);
+ d->parent->mergePropertiesIntoSelection(properties, removeProperties, false, true);
}
bool SvgTextCursorPropertyInterface::spanSelection()
diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.h
index bc1ff7c701..bfa1f1bbf4 100644
--- a/plugins/tools/svgtexttool/SvgTextCursor.h
+++ b/plugins/tools/svgtexttool/SvgTextCursor.h
@@ -202,7 +202,7 @@ public:
QList<KoSvgTextProperties> propertiesForRange() const;
QList<KoSvgTextProperties> propertiesForShape() const;
- void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false);
+ void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false, bool selectWord = false);
/**
* @brief removeSelection
@@ -315,7 +315,7 @@ private:
void updateTypeSettingDecoration();
void addCommandToUndoAdapter(KUndo2Command *cmd);
- int moveModeResult(MoveMode &mode, int &pos, bool visual = false) const;
+ int moveModeResult(const MoveMode mode, int &pos, bool visual = false) const;
bool acceptableInput(const QKeyEvent *event) const;
void commitIMEPreEdit();