aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Editor.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r--src/Editor.cxx36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 2e1467e32..1fb6d960d 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5696,15 +5696,27 @@ Sci::Position Editor::GetTag(char *tagValue, int tagNumber) {
return length;
}
-Sci::Position Editor::ReplaceTarget(bool replacePatterns, const char *text, Sci::Position length) {
+Sci::Position Editor::ReplaceTarget(ReplaceType replaceType, std::string_view text) {
UndoGroup ug(pdoc);
- if (length == -1)
- length = strlen(text);
- if (replacePatterns) {
- text = pdoc->SubstituteByPosition(text, &length);
- if (!text) {
+ if (replaceType == ReplaceType::patterns) {
+ Sci::Position length = text.length();
+ const char *p = pdoc->SubstituteByPosition(text.data(), &length);
+ if (!p) {
return 0;
}
+ text = std::string_view(p, length);
+ }
+
+ if (replaceType == ReplaceType::minimal) {
+ // Check for prefix and suffix and reduce text and target to match.
+ // This is performed with Range which doesn't support virtual space.
+ Range range(targetRange.start.Position(), targetRange.end.Position());
+ pdoc->TrimReplacement(text, range);
+ // Re-apply virtual space to start if start position didn't change.
+ // Don't bother with end as its virtual space is not used
+ const SelectionPosition start(range.start == targetRange.start.Position() ?
+ targetRange.start : SelectionPosition(range.start));
+ targetRange = SelectionSegment(start, SelectionPosition(range.end));
}
// Remove the text inside the range
@@ -5718,9 +5730,9 @@ Sci::Position Editor::ReplaceTarget(bool replacePatterns, const char *text, Sci:
targetRange.end = targetRange.start;
// Insert the new text
- const Sci::Position lengthInserted = pdoc->InsertString(targetRange.start.Position(), text, length);
+ const Sci::Position lengthInserted = pdoc->InsertString(targetRange.start.Position(), text);
targetRange.end.SetPosition(targetRange.start.Position() + lengthInserted);
- return length;
+ return text.length();
}
bool Editor::IsUnicodeMode() const noexcept {
@@ -6240,11 +6252,15 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case Message::ReplaceTarget:
PLATFORM_ASSERT(lParam);
- return ReplaceTarget(false, ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
+ return ReplaceTarget(ReplaceType::basic, ViewFromParams(lParam, wParam));
case Message::ReplaceTargetRE:
PLATFORM_ASSERT(lParam);
- return ReplaceTarget(true, ConstCharPtrFromSPtr(lParam), PositionFromUPtr(wParam));
+ return ReplaceTarget(ReplaceType::patterns, ViewFromParams(lParam, wParam));
+
+ case Message::ReplaceTargetMinimal:
+ PLATFORM_ASSERT(lParam);
+ return ReplaceTarget(ReplaceType::minimal, ViewFromParams(lParam, wParam));
case Message::SearchInTarget:
PLATFORM_ASSERT(lParam);