Mercurial > hg > RemoteEditor > Eclipse
changeset 183:54a9dba5ce2a
*** empty log message ***
author | pin |
---|---|
date | Fri, 12 Sep 2008 13:52:26 +0900 |
parents | f8eab56045c5 |
children | 736fd137d9a3 |
files | bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class src/remoteeditor/editors/RemoteEditor.java |
diffstat | 3 files changed, 43 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/src/remoteeditor/editors/RemoteEditor.java Tue Sep 09 17:39:45 2008 +0900 +++ b/src/remoteeditor/editors/RemoteEditor.java Fri Sep 12 13:52:26 2008 +0900 @@ -80,19 +80,7 @@ repreceive = new REPPacketReceive(sc); repsend = new REPPacketSend(sc); -// IWorkbench workbench = PlatformUI.getWorkbench(); -// Display display = workbench.getDisplay(); -// REPSelectWindow selectwindow = new REPSelectWindow(display); -// selectwindow.initWindow(); -// selectwindow.setName(this.getEditorInput().getName()); -// selectwindow.setChannel(sc); -// selectwindow.open(); - - //REPCommand temp = repreceive.unpack(); - //myeid = temp.eid; mysid = temp.sid; repreceive.addCommandListener(this); - //repsend.send(new REPCommand(REP.REPCMD_READ, mysid, myeid, myseq, 0, 0, "")); - //joinPart(); if(document.getLength() < 1){ joinPart(); }else { @@ -120,75 +108,76 @@ numberOfLinesOld = document.getNumberOfLines(); return; } + String replacedText = event.getReplacedText(); - String inputText = event.getText(); - - //ページ先頭からの文字数による座標(改行を含む) + String inputText = event.getText(); int textOffset = event.getOffset(); - System.out.println("replace = " + replacedText); - System.out.println("input = " + inputText + " : " + inputText.length()); + System.out.println("RemoteEditor.textChanged() : replaceText = " + replacedText); + System.out.println("RemoteEditor.textChanged() : inputText = " + inputText + " : " + inputText.length()); - int line = 0; - int lineOffset = 0; - int length = 0; int numberOfLinesNew = 0; - String lineText = null; - try { - line = document.getNumberOfLines(0, textOffset); // lineno を取得してます。 - lineOffset = document.getLineOffset(line-1); - length = document.getLineLength(line-1); - lineText = document.get(lineOffset, length); - numberOfLinesNew = document.getNumberOfLines(); - } catch (BadLocationException e1) { - e1.printStackTrace(); - } - - String beforeText = getBeforeText(line, lineOffset, inputText, replacedText); + numberOfLinesNew = document.getNumberOfLines(); if(numberOfLinesNew == numberOfLinesOld){ - sendDelete(line, beforeText); - sendInsert(line, lineText); - } - - if(numberOfLinesNew > numberOfLinesOld){ - //insert, delete, replace 行数で判断 - sendInsert(replacedText, inputText, textOffset, line, lineOffset); + sendDelete(textOffset, inputText, replacedText); + sendInsert(textOffset, inputText, replacedText); - }else if(numberOfLinesNew == numberOfLinesOld){ - sendReplace(replacedText, inputText, textOffset, line, lineOffset); + }else if(numberOfLinesNew > numberOfLinesOld){ + sendInsert(textOffset, inputText, replacedText); - }else { - sendDelete(replacedText, inputText, textOffset, line, lineOffset); + }else if(numberOfLinesNew < numberOfLinesOld){ + sendDelete(textOffset, inputText, replacedText); + } numberOfLinesOld = document.getNumberOfLines(); } - private void sendInsert(int line, String lineText) { - // TODO Auto-generated method stub - + private void sendInsert(int textOffset, String inputText, String replacedText){ + int lineno = 0; + String text = null; + try { + lineno = document.getNumberOfLines(0, textOffset); + int lineOffset = document.getLineOffset(lineno-1); //行頭 + int length = document.getLineLength(lineno-1); + text = document.get(lineOffset, length); + } catch (BadLocationException e) { + e.printStackTrace(); + } + REPCommand command = new REPCommand(REP.REPCMD_INSERT, mysid, myeid, myseq++, lineno, text.length(), text); + repsend.send(command); } - private void sendDelete(int line, String beforeText) { - // TODO Auto-generated method stub - + private void sendDelete(int textOffset, String inputText, String replacedText) { + int lineno = 0; + try { + lineno = document.getNumberOfLines(0, textOffset); + } catch (BadLocationException e) { + e.printStackTrace(); + } + String text = getBeforeText(textOffset, inputText, replacedText); + REPCommand command = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, myseq++, lineno, text.length(), text); + repsend.send(command); } - private String getBeforeText(int line, int offset, String inputText, String replacedText) { + private String getBeforeText(int textOffset, String inputText, String replacedText) { String lineText = null; + int offsetInLine = 0; try { - int lineOffset = document.getLineOffset(line-1); - int length = document.getLineLength(line-1); + int lineno = document.getNumberOfLines(0, textOffset); + int lineOffset = document.getLineOffset(lineno-1); + int length = document.getLineLength(lineno-1); lineText = document.get(lineOffset, length); + offsetInLine = textOffset - lineOffset; } catch (BadLocationException e) { e.printStackTrace(); } StringBuffer sb = new StringBuffer(lineText); - sb.delete(offset, offset + inputText.length()); + sb.delete(offsetInLine, offsetInLine + inputText.length()); if(replacedText != null){ - sb.insert(offset, replacedText); + sb.insert(offsetInLine, replacedText); } String beforeText = sb.toString(); return beforeText; @@ -428,7 +417,6 @@ String text = getTextByLineNo(command.lineno); sendCommand = new REPCommand(REP.SMCMD_GET_UNDO_ACK, mysid, myeid, 0, command.lineno, 0, text); } catch (BadLocationException e) { - // TODO Auto-generated catch block e.printStackTrace(); } break;