This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new 24747fdca4 Fix field insertion over selected text in FormulaEditor
(#7780)
24747fdca4 is described below
commit 24747fdca40f6cf70aca80944e8151dc38b4640d
Author: Lance <[email protected]>
AuthorDate: Thu Aug 6 14:44:52 2026 +0800
Fix field insertion over selected text in FormulaEditor (#7780)
Signed-off-by: lance <[email protected]>
---
.../transforms/formula/editor/FormulaEditor.java | 21 ++-------------------
.../transforms/janino/editor/FormulaEditor.java | 21 ++-------------------
2 files changed, 4 insertions(+), 38 deletions(-)
diff --git
a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/editor/FormulaEditor.java
b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/editor/FormulaEditor.java
index 21bc6a6a9b..a1c472a05b 100644
---
a/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/editor/FormulaEditor.java
+++
b/plugins/transforms/formula/src/main/java/org/apache/hop/pipeline/transforms/formula/editor/FormulaEditor.java
@@ -210,25 +210,8 @@ public class FormulaEditor extends Dialog implements
KeyListener {
:
functionLib.getFunctionDescription(item.getText()).getSyntax();
}
- String oldFormula = expressionEditor.getText();
- int caretPosition = expressionEditor.getCaretPosition();
- int textLength = expressionEditor.getText().length();
- int selectionsize = expressionEditor.getSelectionCount();
-
- // No text in editor yet, just add text
- if (textLength == 0) {
- expressionEditor.setText(partToInsert);
- } else if (textLength == caretPosition) {
- // we are at the end of the text, append new text
- expressionEditor.setText(oldFormula + partToInsert);
- } else {
- // Adding text somewhere between other text
- // if selectionsize is > 0 then we are writing over other text
- expressionEditor.setText(
- oldFormula.substring(0, caretPosition)
- + partToInsert
- + oldFormula.substring(caretPosition + selectionsize));
- }
+ // insert() replaces selection regardless of caret direction
(fixes #5321)
+ expressionEditor.insert(partToInsert);
}
}
});
diff --git
a/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/janino/editor/FormulaEditor.java
b/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/janino/editor/FormulaEditor.java
index 20f3168289..8edcc9e5e9 100644
---
a/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/janino/editor/FormulaEditor.java
+++
b/plugins/transforms/janino/src/main/java/org/apache/hop/pipeline/transforms/janino/editor/FormulaEditor.java
@@ -211,25 +211,8 @@ public class FormulaEditor extends Dialog implements
KeyListener {
:
functionLib.getFunctionDescription(item.getText()).getSyntax();
}
- String oldFormula = expressionEditor.getText();
- int caretPosition = expressionEditor.getCaretPosition();
- int textLength = expressionEditor.getText().length();
- int selectionsize = expressionEditor.getSelectionCount();
-
- // No text in editor yet, just add text
- if (textLength == 0) {
- expressionEditor.setText(partToInsert);
- } else if (textLength == caretPosition) {
- // we are at the end of the text, append new text
- expressionEditor.setText(oldFormula + partToInsert);
- } else {
- // Adding text somewhere between other text
- // if selectionsize is > 0 then we are writing over other text
- expressionEditor.setText(
- oldFormula.substring(0, caretPosition)
- + partToInsert
- + oldFormula.substring(caretPosition + selectionsize));
- }
+ // insert() replaces selection regardless of caret direction
(fixes #5321)
+ expressionEditor.insert(partToInsert);
}
}
});