Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Setting document text without losing cursor position?
Setting document text without losing cursor position? [message #323921] Sun, 13 January 2008 05:48 Go to next message
Eclipse UserFriend
Originally posted by: sascha.pasalacqua.de

Hi,

we are currently working on a simple text editor. We provide our own
simple document provider and document (which is just an extended Document
(class)).

There are times when we have to replace the whole text of the document by
calling IDocument.set(...).

The problem: After calling .set(...) the text editor scrolls to the top
and sets the cursor to line 1.

We would like to avoid this and keep the current cursor position since
often the new text is quite similar to the replaced text.

But how to ? Why does the editor scroll up to the top at all ?

Thanks in advance!

Sascha
Re: Setting document text without losing cursor position? [message #323984 is a reply to message #323921] Tue, 15 January 2008 08:39 Go to previous message
Eclipse UserFriend
Sascha wrote:

> Hi,
>
> we are currently working on a simple text editor. We provide our own
> simple document provider and document (which is just an extended
> Document (class)).
>
> There are times when we have to replace the whole text of the document
> by calling IDocument.set(...).
>
> The problem: After calling .set(...) the text editor scrolls to the
> top and sets the cursor to line 1.
>
> We would like to avoid this and keep the current cursor position since
> often the new text is quite similar to the replaced text.

If it is quite similar, why don't you change it using text edits instead
of replacing the whole document? If the position is really the same you can
1. get the selection from the editor's selection provider
2. replace the doc
3. set the selection from step 1 to the selection provider

Dani

>
> But how to ? Why does the editor scroll up to the top at all ?
>
> Thanks in advance!
>
> Sascha
>
Previous Topic:Interface Selection Wizard Component
Next Topic:Autocomplete takes ages to load javadocs
Goto Forum:
  


Current Time: Thu Jul 17 23:16:21 EDT 2025

Powered by FUDForum. Page generated in 0.72883 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top