How to let IntelliJ IDEA's Local History ignore Plugins' temporary change and restore to document?

StackOverflow https://stackoverflow.com/questions/14303854

  •  15-01-2022
  •  | 
  •  

Question

I am writing a IntelliJ IDEA plugin at here like AceJump, which is used for fast move caret in IDE.

like following, by apply TextAttributes to all 'i' occurrences, and give each 'i' an index char.

enter image description here

after user press 'H', the caret will move to 'i' in the "private". then change all Markup chars to original 'i'

PROBLEMS

  1. This action will change the Document contents during jump. so there will be a history change like below. Is there a way to ignore the changes in Local History management?

  2. After press Cmd-z, there is a dialog says "Cannot Undo". how to avoid this?

enter image description here

enter image description here

Was it helpful?

Solution

Instead of changing the document contents, you should paint your navigation markers over the document using, for example, the HintManager class.

If you change the actual document contents, this will have many more consequences besides breaking undo and local history - for example, the document will be reparsed causing false syntax errors to be displayed; any other plugin or IntelliJ IDEA component watching for changes to the document will react to this; the document will be checked out from the VCS if the user is using a VCS such as Perforce that requires an explicit checkout operation; etc. TL/DR: don't do that.

OTHER TIPS

In case someone google and find here. following is my final solution.

I using Swing graphics drawing to show the markers, works great.

please refer for details: https://github.com/whunmr/emacsIDEAs/blob/master/src/org/hunmr/acejump/marker/MarkersPanel.java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top