Mercurial > hg > RemoteEditor > Eclipse
changeset 135:cdcd9fcd5dbf
*** empty log message ***
author | pin |
---|---|
date | Tue, 22 Jan 2008 18:57:36 +0900 |
parents | 1e033a92b69a |
children | 5b6afb5641ac |
files | bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class src/remoteeditor/editors/RemoteEditor.java |
diffstat | 3 files changed, 27 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/remoteeditor/editors/RemoteEditor.java Tue Jan 22 15:50:03 2008 +0900 +++ b/src/remoteeditor/editors/RemoteEditor.java Tue Jan 22 18:57:36 2008 +0900 @@ -158,8 +158,8 @@ //insert, delete, replace 行数で判断 cmd = REP.REPCMD_INSERT; try { - createUndoCommand(cmd, replacedText, inputText, line); sendInsert(line); + createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); } catch (BadLocationException e) { e.printStackTrace(); } @@ -168,6 +168,7 @@ cmd = REP.REPCMD_REPLACE; try { sendReplace(line); + createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); } catch (BadLocationException e) { e.printStackTrace(); } @@ -191,20 +192,41 @@ numberOfLinesOld = numberOfLinesNew; } - private void createUndoCommand(int cmd, String replacedText, String inputText, int line) { + private void createUndoCommand(int cmd, int offset, String replacedText, String inputText, int line) { int undoCmd = 0; String undoString = null; REPCommand undoCommand; REPPacketSend send = new REPPacketSend(sc); + if(cmd == REP.REPCMD_INSERT){ undoCmd = REP.REPCMD_DELETE; undoString = ""; + }else if(cmd == REP.REPCMD_REPLACE){ undoCmd = REP.REPCMD_REPLACE; + String lineText = null; + try { + int lineOffset = document.getLineOffset(line-1); + int length = document.getLineLength(line-1); + lineText = document.get(lineOffset, length); + } catch (BadLocationException e) { + e.printStackTrace(); + } + undoString = lineText; + //StringBuffer sb = new StringBuffer(lineText); + //sb.insert(offset, inputText); + //if(replacedText == null){ + // sb.delete(offset, inputText.length()); + //}else { + //sb.replace(offset, inputText.length(), replacedText); + //} + //undoString = sb.toString(); + }else if(cmd == REP.REPCMD_DELETE){ undoCmd = REP.REPCMD_INSERT; undoString = replacedText; } + undoCommand = new REPCommand(undoCmd, mysid, 0, -1, line, undoString.length(), undoString); send.send(undoCommand); } @@ -251,7 +273,8 @@ } } - public void changeText(int kindOfCmd, int lineNo, int LineLength, String text) throws Exception{ + private void changeText(int kindOfCmd, int lineNo, int LineLength, String text) throws Exception{ + System.out.println("Replace Text : " + text); final int offset = document.getLineOffset(lineNo-1); final String changedText = text; @@ -338,7 +361,7 @@ case REP.REPCMD_REPLACE: try { if(command.eid == myeid) break;//mergerを導入する時に消す - repsend.send(command); + if(command.seq > 0) repsend.send(command); changeText(command.cmd, command.lineno, command.len, command.string); } catch (Exception e1) { e1.printStackTrace();