Dave Jarvis' Repositories

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

Implemented desired behaviour for advancing through nodes by finding nodes based on dot-separated paths.

Authordjarvis <email>
Date2016-11-06 11:44:47 GMT-0800
Commitd7b93d68874ed63e729a9536b792bcf8313290db
Parent2a5824e
Delta27 lines added, 19 lines removed, 8-line increase
src/main/java/com/scrivendor/editor/VariableEditor.java
*/
public class VariableEditor {
+
/**
* Used to capture keyboard events once the user presses @.
if( posEnded - posBegan > 0 ) {
- t.selectRange( posEnded, posBegan );
+ t.selectRange( posBegan, posEnded );
}
System.out.println( "Inserted: '" + text + "'" );
System.out.println( "Selected: '" + t.getSelectedText() + "'" );
}
-
+
/**
* Updates the text with the path selected (or typed) by the user.
*/
private void advancePath() {
+ final String word = getCurrentWord();
+ final TreeItem<String> node = findNearestNode( word );
+ String text = node.getValue();
+
System.out.println( "----------" );
System.out.println( "advancePath" );
-
- final String path = getPath();
- final TreeItem<String> node = findNearestNode( path );
-// final DefinitionPane pane = getDefinitionPane();
-// final String word = pane.computeLastWord( path );
-
- expand( node );
-
- String typeAhead = node.getValue();
if( !node.isLeaf() ) {
- node.setExpanded( true );
+ System.out.println( "word = '" + word + "'" );
+ System.out.println( "node = '" + node.getValue() + "'" );
+// final TreeItem<String> child = getFirst( node.getChildren() );
// TODO: Magically decide how much of the path overlaps the node.
// final String nodeValue = node.getValue();
// final int index = nodeValue.indexOf( word );
//
// if( index == 0 && !nodeValue.equals( word ) ) {
// typeAhead = nodeValue.substring( word.length() );
// }
}
- updateEditorText( typeAhead );
+ updateEditorText( text );
}
*/
private void cycleSelection( final boolean direction ) {
- final String path = getPath();
+ final String path = getCurrentWord();
final TreeItem<String> node = findNearestNode( path );
+
+ System.out.println( "---------------" );
+ System.out.println( "cycle selection" );
+ System.out.println( "path = '" + path + "'" );
// Find the sibling for the current selection and replace the current
cycled = direction ? getFirstSibling( node ) : getLastSibling( node );
}
+
+ System.out.println( "cycled value = '" + cycled.getValue() + "'" );
expand( cycled );
* @return A non-null string, possibly empty.
*/
- private String getPath() {
+ private String getCurrentWord() {
final String p = getCurrentParagraph();
final String s = p.substring( getInitialCaretColumn() );
- int index = 0;
+ int i = 0;
- while( index < s.length() && !Character.isWhitespace( s.charAt( index ) ) ) {
- index++;
+ while( i < s.length() && !Character.isWhitespace( s.charAt( i ) ) ) {
+ i++;
}
- return p.substring( getInitialCaretColumn(), index );
+ final String word = p.substring( getInitialCaretColumn(), i );
+
+ System.out.println( "Current word: '" + word + "'" );
+
+ return word;
}