Question simplified: is it possible to temporary change text in editor without changing underlying document?

Hello, folks.

Is  it possible to temporary change text in editor without actually  changing underlying document? Using document.replaceString(...) breaks  undo history and marks file as modified (star symbol). I need just to  change text visually, without background re-validation.

Thanks in advance.

10 comments

Great suggestion.

I did implement it with folding but unfortunately now I can't change letter colors within folded text. Also, folded text length must be more than one character:

    if (startOffset + 1 >= endOffset) {
      LOG.error("Invalid offsets: ("+startOffset+", "+endOffset+")");
    }


Very strange limitation (I need to temporary change and highlight single characters).

0

That is strange, although thinking about it it makes sense - folding was initially designed to collapse large sections of text into smaller ones, and you can't collapse a single character into anything smaller. I'm out of suggestions for what you want to achieve, sorry - you can change the colour with highlighters but folding is the only way I know of to substitute text content.

0

Why don't you simply use the IdeGlassPane interface to paint whatever you need over the editor text without modifying anything?

0

Thanks, it's an option but this is radically different in terms of editor extensibility and implementation. I just needed to "mask" some text and change it's style/colors - not to draw something on top. Having no other options, I'm currently trying to implement your solution, need to figure out how to get each needed character position withing editor content component, how to set similar background and text style, and so on.

0

This is all fairly easy to do. See for example Editor.logicalPositionToXY() method.

IntelliJ IDEA's architecture is not designed in any way for transient modifications of editor text or markup, and if you go that way, you'll always need to struggle against the codebase. Drawing things on top of the editor, on the other hand, is something that we use ourselves at times, and does not conflict against the design in any way.

0

Mega-thanks to you both, guys. It seems to be working.

0

Hi there,

Your link seems 404 now; But I believe your plugin may be similiar to the following plugins - so they might be good to check out too

http://plugins.jetbrains.com/plugin/?idea_ce&pluginId=7163
http://plugins.jetbrains.com/plugin/7086?pr=ruby

cheers

0

Please sign in to leave a comment.