| | */ |
| | private static final Options sOptions = Services.load( Options.class ); |
| | - private static final Snitch SNITCH = Services.load( Snitch.class ); |
| | + private static final Snitch sSnitch = Services.load( Snitch.class ); |
| | |
| | private final Scene mScene; |
 |
| | |
| | private final ChangeListener<Integer> mCaretPositionListener = |
| | - ( observable, oldPosition, newPosition ) -> { |
| | - processActiveTab(); |
| | - }; |
| | + ( observable, oldPosition, newPosition ) -> processActiveTab(); |
| | |
| | private DefinitionSource mDefinitionSource = createDefaultDefinitionSource(); |
 |
| | initDefinitionListener(); |
| | initTabAddedListener(); |
| | - initTabChangedListener(); |
| | + |
| | initPreferences(); |
| | initVariableNameInjector(); |
| | + |
| | + addShowListener(getScene().getRoot(), ( __ ) -> { |
| | + initTabChangedListener(); |
| | + }); |
| | } |
| | |
 |
| | */ |
| | private void initSnitch() { |
| | - SNITCH.addObserver( this ); |
| | + sSnitch.addObserver( this ); |
| | } |
| | |
 |
| | /** |
| | * When tabs are added, hook the various change listeners onto the new |
| | - * tab sothat the preview pane refreshes as necessary. |
| | + * tab so that the preview pane refreshes as necessary. |
| | */ |
| | private void initTabAddedListener() { |
| | final FileEditorTabPane editorPane = getFileEditorPane(); |
| | |
| | // Make sure the text processor kicks off when new files are opened. |
| | final ObservableList<Tab> tabs = editorPane.getTabs(); |
| | |
| | - // Update the preview pane on tab changes. |
| | tabs.addListener( |
| | ( final Change<? extends Tab> change ) -> { |
| | while( change.next() ) { |
| | if( change.wasAdded() ) { |
| | // Multiple tabs can be added simultaneously. |
| | for( final Tab newTab : change.getAddedSubList() ) { |
| | final FileEditorTab tab = (FileEditorTab) newTab; |
| | |
| | - initTextChangeListener( tab ); |
| | initScrollEventListener( tab ); |
| | initSpellCheckListener( tab ); |
| | + initTextChangeListener( tab ); |
| | // initSyntaxListener( tab ); |
| | } |
| | } |
| | + } |
| | + } |
| | + ); |
| | + } |
| | + |
| | + /** |
| | + * Listen for new tab selection events. |
| | + */ |
| | + private void initTabChangedListener() { |
| | + final FileEditorTabPane editorPane = getFileEditorPane(); |
| | + |
| | + // Update the preview pane changing tabs. |
| | + editorPane.addTabSelectionListener( |
| | + ( __, oldTab, newTab ) -> { |
| | + if( newTab == null ) { |
| | + // Clear the preview pane when closing an editor. When the last |
| | + // tab is closed, this ensures that the preview pane is empty. |
| | + getHtmlPreview().clear(); |
| | + } |
| | + else { |
| | + final var tab = (FileEditorTab) newTab; |
| | + updateVariableNameInjector( tab ); |
| | + process( tab ); |
| | } |
| | } |
 |
| | .filter( p -> !p.isIdentity() ).subscribe( change -> { |
| | |
| | - // Only perform a spell check on the current paragraph. The |
| | - // entire document is processed once, when opened. |
| | + // Check current paragraph; the whole document was checked upon opening. |
| | final var offset = change.getPosition(); |
| | final var position = editor.offsetToPosition( offset, Forward ); |
| | final var paraId = position.getMajor(); |
| | final var paragraph = editor.getParagraph( paraId ); |
| | final var text = paragraph.getText(); |
| | |
| | - // Ensure that styles aren't doubled-up. |
| | + // Prevent doubling-up styles. |
| | editor.clearStyle( paraId ); |
| | |
| | spellcheck( editor, text, paraId ); |
| | } ); |
| | - } |
| | - |
| | - /** |
| | - * Listen for new tab selection events. |
| | - */ |
| | - private void initTabChangedListener() { |
| | - final FileEditorTabPane editorPane = getFileEditorPane(); |
| | - |
| | - // Update the preview pane changing tabs. |
| | - editorPane.addTabSelectionListener( |
| | - ( __, oldTab, newTab ) -> { |
| | - if( newTab == null ) { |
| | - // Clear the preview pane when closing an editor. When the last |
| | - // tab is closed, this ensures that the preview pane is empty. |
| | - getHtmlPreview().clear(); |
| | - } |
| | - else { |
| | - final var tab = (FileEditorTab) newTab; |
| | - updateVariableNameInjector( tab ); |
| | - process( tab ); |
| | - } |
| | - } |
| | - ); |
| | } |
| | |