# HG changeset patch # User pin # Date 1200995856 -32400 # Node ID cdcd9fcd5dbf11453d0e90440f5774b535d3c0d6 # Parent 1e033a92b69a5c61a60a8031bf627a6a0b4cf2ab *** empty log message *** diff -r 1e033a92b69a -r cdcd9fcd5dbf bin/remoteeditor/editors/RemoteEditor$1.class Binary file bin/remoteeditor/editors/RemoteEditor$1.class has changed diff -r 1e033a92b69a -r cdcd9fcd5dbf bin/remoteeditor/editors/RemoteEditor.class Binary file bin/remoteeditor/editors/RemoteEditor.class has changed diff -r 1e033a92b69a -r cdcd9fcd5dbf src/remoteeditor/editors/RemoteEditor.java --- 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();