Skip to content

Commit

Permalink
Better Insersion
Browse files Browse the repository at this point in the history
  • Loading branch information
KnIlight committed Sep 11, 2020
1 parent e5e19b8 commit 205b70f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ui/PathToolDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void InjectBG(boolean inject) {
universal_buffer.setLength(0);
universal_buffer.append(data, 0, removeSt-1);
universal_buffer.append(data, removeEd+1, length);
tweaker.setDocumentText(universal_buffer);
tweaker.setDocumentText(universal_buffer, -(removeEd-removeSt+2));
}
}
if(!removed) {
Expand All @@ -170,7 +170,7 @@ private void InjectBG(boolean inject) {
universal_buffer.append(data, 0, insIdx);
universal_buffer.append(text);
universal_buffer.append(data, insIdx, length);
tweaker.setDocumentText(universal_buffer);
tweaker.setDocumentText(universal_buffer, text.length());
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/ui/PathTweakerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,15 @@ private void doIt() {
}
}

void setDocumentText(CharSequence text) {
void setDocumentText(CharSequence text, int selOffset) {
if(mDocument!=null){
WriteCommandAction.runWriteCommandAction(mProject, ()-> mDocument.setText(text));
WriteCommandAction.runWriteCommandAction(mProject, ()-> {
mDocument.setText(text);
if(currentStart<currentEnd && currentStart>=0) {
currentStart+=selOffset;
currentEnd+=selOffset;
}
});
}
}

Expand Down

0 comments on commit 205b70f

Please sign in to comment.