[Jreepad-CVS] jreepad/src/jreepad JreepadView.java,1.39,1.40
Brought to you by:
danstowell
From: PeWu <pe...@us...> - 2007-02-07 17:39:33
|
Update of /cvsroot/jreepad/jreepad/src/jreepad In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18867/src/jreepad Modified Files: JreepadView.java Log Message: moved selectWordUnderCursor() to PlainTextEditor; code cleanup Index: JreepadView.java =================================================================== RCS file: /cvsroot/jreepad/jreepad/src/jreepad/JreepadView.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** JreepadView.java 6 Feb 2007 20:58:01 -0000 1.39 --- JreepadView.java 7 Feb 2007 17:39:16 -0000 1.40 *************** *** 274,301 **** private void setCurrentNode(JreepadNode n) { ! boolean isSame = currentNode!=null && n.equals(currentNode); ! //System.out.println("setCurrentNode() activated: sameness test = "+isSame); ! // ! // This "isSame" test should stop the caret jumping to the end of the text when we press Save. ! // ! if(isSame) ! { ! // Only update the node's stored content if it's a plaintext node ! if(currentNode.getArticle().getArticleMode() == JreepadArticle.ARTICLEMODE_ORDINARY) ! currentNode.getArticle().setContent(getEditorPaneText()); return; - } editorPanePlainText.lockEdits(); // Deactivate the caret-listener, effectively - ALSO DEACTIVATES UNDO-STORAGE - if(currentNode != null) - { - // Only update the node's stored content if it's a plaintext node - if(currentNode.getArticle().getArticleMode() == JreepadArticle.ARTICLEMODE_ORDINARY) - currentNode.getArticle().setContent(getEditorPaneText()); - } currentNode = n; setEditorPaneText(n.getArticle()); ensureCorrectArticleRenderMode(); editorPanePlainText.unlockEdits(); // Reactivate the caret listener - ALSO REACTIVATES UNDO-STORAGE } --- 274,287 ---- private void setCurrentNode(JreepadNode n) { ! // This should stop the caret jumping to the end of the text when we press Save. ! if (currentNode == n) return; editorPanePlainText.lockEdits(); // Deactivate the caret-listener, effectively - ALSO DEACTIVATES UNDO-STORAGE currentNode = n; setEditorPaneText(n.getArticle()); ensureCorrectArticleRenderMode(); + editorPanePlainText.unlockEdits(); // Reactivate the caret listener - ALSO REACTIVATES UNDO-STORAGE } *************** *** 308,312 **** public JreepadNode getRootJreepadNode() { - setCurrentNode(getCurrentNode()); // Ensures any edits have been committed return root; } --- 294,297 ---- *************** *** 660,690 **** if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) ! { ! try ! { ! ! String text = getEditorPaneText(); ! int startpos = editorPanePlainText.getCaretPosition(); ! int endpos = startpos; ! if(text.length()>0) ! { ! // Select the character before/after the current position, and grow it until we hit whitespace... ! while(startpos>0 && !Character.isWhitespace(editorPanePlainText.getText(startpos-1,1).charAt(0))) ! startpos--; ! while(endpos<(text.length()) && !Character.isWhitespace(editorPanePlainText.getText(endpos,1).charAt(0))) ! endpos++; ! if(endpos>startpos) ! { ! editorPanePlainText.setSelectionStart(startpos); ! editorPanePlainText.setSelectionEnd(endpos); ! url = editorPanePlainText.getSelectedText(); ! } ! } ! } ! catch(BadLocationException err) ! { ! System.out.println(err); ! } ! } if(url==null || !(url.length()>0)) --- 645,649 ---- if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) ! url = editorPanePlainText.selectWordUnderCursor(); if(url==null || !(url.length()>0)) *************** *** 703,732 **** String url = getSelectedTextInArticle(); if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) ! { ! try ! { ! ! String text = getEditorPaneText(); ! int startpos = editorPanePlainText.getCaretPosition(); ! int endpos = startpos; ! if(text != null) ! { ! // Select the character before/after the current position, and grow it until we hit whitespace... ! while(startpos>0 && !Character.isWhitespace(editorPanePlainText.getText(startpos-1,1).charAt(0))) ! startpos--; ! while(endpos<(text.length()) && !Character.isWhitespace(editorPanePlainText.getText(endpos,1).charAt(0))) ! endpos++; ! if(endpos>startpos) ! { ! editorPanePlainText.setSelectionStart(startpos); ! editorPanePlainText.setSelectionEnd(endpos); ! url = editorPanePlainText.getSelectedText(); ! } ! } ! } ! catch(BadLocationException err) ! { ! } ! } openURL(url); } --- 662,666 ---- String url = getSelectedTextInArticle(); if((url == null) && (currentNode.getArticle().getArticleMode()==JreepadArticle.ARTICLEMODE_ORDINARY)) ! url = editorPanePlainText.selectWordUnderCursor(); openURL(url); } *************** *** 1029,1033 **** editorPanePlainText.lockEdits(); // Disables store-for-undo - currentNode.getArticle().setContent(editorPanePlainText.getText()); switch(newMode) { --- 963,966 ---- |