Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Fix code comments, reorg method

AuthorDaveJarvis <email>
Date2020-11-11 23:29:37 GMT-0800
Commit1435ae5f6abafaa4a341ed5a7a2cd55c1139eb95
Parent92db824
Delta36 lines added, 39 lines removed, 3-line decrease
src/main/resources/com/keenwrite/preview/webview.css
-/* RESET ***/
html{box-sizing:border-box;font-size:12pt}body,h1,h2,h3,h4,h5,h6,ol,p,ul{margin:0;padding:0}img{max-width:100%;height:auto}table{table-collapse:collapse;table-spacing:0;border-spacing:0}
-/* BODY ***/
body {
/* Must be bundled in JAR file. */
max-width: 100%;
- /**
- * Required for FlyingSaucer to treat images
+ /* Required for FlyingSaucer to treat images
* as block elements. See SvhReplacedElementFactory
* for details.
src/main/java/com/keenwrite/MainWindow.java
*/
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 );
- }
- }
- );
}