Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Custom Editor Saving File causes cursor position to be reset
Custom Editor Saving File causes cursor position to be reset [message #333303] Wed, 03 December 2008 17:26
Mike Jackson is currently offline Mike JacksonFriend
Messages: 128
Registered: July 2009
Senior Member
I my custom editor CMakeEditor which extends from TextEditor
(cmakeed.sourceforge.net) when the user "saves" the document, the
cursor is reset to the top of the file which isn't exactly friendly. I
have some code to stop this from happening but it seems awfully like a
"kludge" rather than doing it the "correct" way.

Here is my current code foe the doSave(IProgressMonitor prog) method:

public void doSave(IProgressMonitor prog)
{
super.doSave(prog);
UIPlugin.getDefault().getCMakePartitionScanner().setDefaultS cannerRules();
IDocument document = this.getSourceViewer().getDocument();
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3 = (IDocumentExtension3) document;
IDocumentPartitioner partitioner =
extension3.getDocumentPartitioner(UIPlugin.CMAKE_PARTITIONIN G);
if (partitioner != null)
{
partitioner.disconnect();
partitioner.connect(document);
// Reinit the syntax coloring
final SourceViewer sourceViewer = (SourceViewer)getSourceViewer();
int line = sourceViewer.getTopIndex();
ITextSelection sel = (ITextSelection)sourceViewer.getSelection();
sourceViewer.unconfigure();
final CMakeEditorConfiguration config =
new CMakeEditorConfiguration(this.colorMgr);
sourceViewer.configure(config);
sourceViewer.refresh();
sourceViewer.setTopIndex(line);
sourceViewer.setSelectedRange(sel.getOffset(), sel.getLength() );
}

}
UIPlugin.getDefault().getCMakePartitionScanner().removeUserV ariableRule();
}

Any help would be greatly appreciated. Or point me to an example that
has the desired behavior and I can try an work from that.

Mike Jackson
BlueQuartz Software
www.bluequartz.net
Previous Topic:ViewPart State & Customize label
Next Topic:No Syntax coloring when opening a file with custom editor
Goto Forum:
  


Current Time: Sat Jul 27 13:21:16 GMT 2024

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

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

Back to the top