From 2664668d2417c32d12faeb71306a6ba97553c432 Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Sat, 6 Jul 2013 00:59:09 +0530 Subject: [PATCH] text insert bug fix --- .../mode/experimental/ASTGenerator.java | 4 +- .../mode/experimental/CompletionPanel.java | 3 +- .../mode/experimental/TextArea.java | 71 +++++++------------ 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 2f1f3e03e..87f7e8718 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -790,7 +790,7 @@ public class ASTGenerator { // CompletionCandidate[] candidatesArray = candidates // .toArray(new CompletionCandidate[candidates.size()]); errorCheckerService.getEditor().textArea() - .showSuggestion(defListModel); + .showSuggestion(defListModel,word); } }; @@ -1376,7 +1376,7 @@ public class ASTGenerator { worker.execute(); } }); - // TODO: Diable this listner at deployment + btnListOccurrence.addActionListener(new ActionListener() { @Override diff --git a/pdex/src/processing/mode/experimental/CompletionPanel.java b/pdex/src/processing/mode/experimental/CompletionPanel.java index b18b28d12..6b853e10d 100644 --- a/pdex/src/processing/mode/experimental/CompletionPanel.java +++ b/pdex/src/processing/mode/experimental/CompletionPanel.java @@ -98,8 +98,9 @@ public class CompletionPanel { public boolean insertSelection() { if (completionList.getSelectedValue() != null) { try { - final String selectedSuggestion = ((CompletionCandidate) completionList + String selectedSuggestion = ((CompletionCandidate) completionList .getSelectedValue()).getCompletionString().substring(subWord.length()); + System.err.println(subWord+" <= subword,Inserting suggestion=> " + selectedSuggestion); textarea.getDocument().insertString(insertionPosition, selectedSuggestion, null); textarea.setCaretPosition(insertionPosition diff --git a/pdex/src/processing/mode/experimental/TextArea.java b/pdex/src/processing/mode/experimental/TextArea.java index 808611f3c..b51c522d8 100644 --- a/pdex/src/processing/mode/experimental/TextArea.java +++ b/pdex/src/processing/mode/experimental/TextArea.java @@ -249,6 +249,17 @@ public class TextArea extends JEditTextArea { } private String fetchPhrase(KeyEvent evt) { + char keyChar = evt.getKeyChar(); + if (keyChar == KeyEvent.VK_ENTER) { + System.out.println("Enter consumed."); + return null; + } +// if (keyChar == KeyEvent.VK_BACK_SPACE || keyChar == KeyEvent.VK_DELETE) +// ; // accepted these keys + else if (keyChar == KeyEvent.CHAR_UNDEFINED) { + return null; + } + int off = getCaretPosition(); System.out.print("off " + off); if (off < 0) @@ -268,17 +279,7 @@ public class TextArea extends JEditTextArea { if(x >= s.length() || x < 0) return null; //TODO: Does this check cause problems? Verify. System.out.print(" x char: " + s.charAt(x)); - //int xLS = off - getLineStartNonWhiteSpaceOffset(line); - char keyChar = evt.getKeyChar(); - if(keyChar == KeyEvent.VK_ENTER){ - System.out.println("Enter consumed."); - return null; - } - if (keyChar == KeyEvent.VK_BACK_SPACE || keyChar == KeyEvent.VK_DELETE) - ; // accepted these keys - else if (keyChar == KeyEvent.CHAR_UNDEFINED) - - return null; + //int xLS = off - getLineStartNonWhiteSpaceOffset(line); String word = (x < s.length() ? s.charAt(x) : "") + ""; if (s.trim().length() == 1) { @@ -651,58 +652,38 @@ public class TextArea extends JEditTextArea { }); } - public void showSuggestionLater(final DefaultListModel defListModel) { + public void showSuggestionLater(final DefaultListModel defListModel, final String word) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - showSuggestion(defListModel); + showSuggestion(defListModel,word); } }); } - protected void showSuggestion(DefaultListModel defListModel) { - if(defListModel.size() == 0){ + protected void showSuggestion(DefaultListModel defListModel,String subWord) { + if (defListModel.size() == 0) { return; } - String subWord = null; int position = getCaretPosition(); -// if (suggestion == null || !suggestion.isVisible()) { - Point location = new Point(); - try { - location.x = offsetToX(getCaretLine(), position - - getLineStartOffset(getCaretLine())); - location.y = lineToY(getCaretLine()) - + getPainter().getFontMetrics().getHeight(); - } catch (Exception e2) { - e2.printStackTrace(); - return; - } - -// } - - String text = getText(); - int start = Math.max(0, position - 1); - while (start > 0) { - if (!Character.isWhitespace(text.charAt(start))) { - start--; - } else { - start++; - break; - } - } - - if (start > position) { + Point location = new Point(); + try { + location.x = offsetToX(getCaretLine(), position + - getLineStartOffset(getCaretLine())); + location.y = lineToY(getCaretLine()) + + getPainter().getFontMetrics().getHeight(); + } catch (Exception e2) { + e2.printStackTrace(); return; } - subWord = text.substring(start, position); if (subWord.length() < 2) { return; } - if(suggestion == null) + if (suggestion == null) suggestion = new CompletionPanel(this, position, subWord, defListModel, - location); + location); else suggestion.updateList(defListModel, subWord, position);