-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract and use DocumentListenerImpl
- Loading branch information
Showing
3 changed files
with
47 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...jboss.tools.aesh.ui/src/org/jboss/tools/aesh/ui/internal/viewer/DocumentListenerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jboss.tools.aesh.ui.internal.viewer; | ||
|
||
import org.eclipse.jface.text.DocumentEvent; | ||
import org.eclipse.jface.text.IDocumentListener; | ||
import org.eclipse.swt.custom.StyleRange; | ||
import org.jboss.tools.aesh.ui.internal.document.DocumentImpl; | ||
import org.jboss.tools.aesh.ui.internal.document.StyleImpl; | ||
|
||
public class DocumentListenerImpl implements IDocumentListener { | ||
|
||
private TextWidget textWidget; | ||
private DocumentImpl document; | ||
|
||
public DocumentListenerImpl(TextWidget textWidget, DocumentImpl document) { | ||
this.textWidget = textWidget; | ||
this.document = document; | ||
} | ||
|
||
@Override | ||
public void documentAboutToBeChanged(DocumentEvent event) { | ||
} | ||
|
||
@Override | ||
public void documentChanged(final DocumentEvent event) { | ||
if (textWidget != null && !textWidget.isDisposed()) { | ||
int lineCount = textWidget.getLineCount(); | ||
textWidget.setTopIndex(lineCount - 1); | ||
StyleImpl style = (StyleImpl)document.getCurrentStyle(); | ||
StyleRange styleRange = style.getStyleRange(); | ||
if (styleRange != null && | ||
event.getLength() == 0 && | ||
styleRange.start <= document.getLength() && | ||
styleRange.length >= 0 && | ||
styleRange.start + styleRange.length <= document.getLength()) { | ||
textWidget.setStyleRange(styleRange); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters