Changing file content without scroll reset [message #464127] |
Mon, 26 February 2007 09:03  |
Eclipse User |
|
|
|
Hi all,
I am writing a preprocessor plugin that comments bits of the code based
on preprocessing directives.
following advice from here, I hooked into stateChanging(IFileBuffer),
and replaces single lines that changes.
this worked until I introduced an #include directive, that can change
the line numbers.
this makes it really hard to replace just that section that changed in
the document, so I am looking for an alternative solution for the
problem of replacing the content of the file without the scroll being
effected.
any thoughts?
maybe I can restore the scroll myself after I change the content of the
IBuffer? if so, how can I do that?
thanks,
|
|
|
Re: Changing file content without scroll reset [message #464134 is a reply to message #464127] |
Mon, 26 February 2007 09:56  |
Eclipse User |
|
|
|
Found a solution!
AbstractDocument document = (AbstractDocument) fileBuffer.getDocument();
DocumentRewriteSession session =
document.startRewriteSession(DocumentRewriteSessionType.UNRE STRICTED);
document.set(text);
document.stopRewriteSession(session);
This magically preserves the scroll position.
Omry Yadan wrote:
> Hi all,
> I am writing a preprocessor plugin that comments bits of the code based
> on preprocessing directives.
>
> following advice from here, I hooked into stateChanging(IFileBuffer),
> and replaces single lines that changes.
> this worked until I introduced an #include directive, that can change
> the line numbers.
> this makes it really hard to replace just that section that changed in
> the document, so I am looking for an alternative solution for the
> problem of replacing the content of the file without the scroll being
> effected.
>
> any thoughts?
> maybe I can restore the scroll myself after I change the content of the
> IBuffer? if so, how can I do that?
>
> thanks,
|
|
|
Powered by
FUDForum. Page generated in 0.06795 seconds