Skip to content

Commit 205b70f

Browse files
committed
Better Insersion
1 parent e5e19b8 commit 205b70f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/ui/PathToolDialog.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void InjectBG(boolean inject) {
154154
universal_buffer.setLength(0);
155155
universal_buffer.append(data, 0, removeSt-1);
156156
universal_buffer.append(data, removeEd+1, length);
157-
tweaker.setDocumentText(universal_buffer);
157+
tweaker.setDocumentText(universal_buffer, -(removeEd-removeSt+2));
158158
}
159159
}
160160
if(!removed) {
@@ -170,7 +170,7 @@ private void InjectBG(boolean inject) {
170170
universal_buffer.append(data, 0, insIdx);
171171
universal_buffer.append(text);
172172
universal_buffer.append(data, insIdx, length);
173-
tweaker.setDocumentText(universal_buffer);
173+
tweaker.setDocumentText(universal_buffer, text.length());
174174
}
175175
}
176176
}

src/ui/PathTweakerDialog.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,15 @@ private void doIt() {
552552
}
553553
}
554554

555-
void setDocumentText(CharSequence text) {
555+
void setDocumentText(CharSequence text, int selOffset) {
556556
if(mDocument!=null){
557-
WriteCommandAction.runWriteCommandAction(mProject, ()-> mDocument.setText(text));
557+
WriteCommandAction.runWriteCommandAction(mProject, ()-> {
558+
mDocument.setText(text);
559+
if(currentStart<currentEnd && currentStart>=0) {
560+
currentStart+=selOffset;
561+
currentEnd+=selOffset;
562+
}
563+
});
558564
}
559565
}
560566

0 commit comments

Comments
 (0)