!7 !include #1006440 // Concepts sclass EditRecorder { Session session; // editor state S text = ""; int caret; bool verbose = true; // update the text void update(S newText) { S a = text, b = newText; int i = lCommonPrefix(a, b); a = substring(a, i); b = substring(b, i); int j = lCommonSuffix(a, b); a = substring(a, 0, l(a)-j); b = substring(b, 0, l(b)-j); // Now differing part remains in a and b; // i and j give length of unchanged beginning+end if (empty(a) && empty(b)) { if (verbose) print("no change"); ret; } EChange change = cnew(EChange, +session, startIndex := i, endIndex := i+l(a), text := b); if (verbose) print("change: " + renderConcept(change)); // Verify the change we made assertEquals(newText, replayEdit(change, text)); text = newText; } void updateCaret(int pos) { if (pos != caret) { cnew(ECaret, +session, +pos); caret = pos; } } } static Session session; static JTextArea ta; static EditRecorder er; p-substance { db(); // persistence session = new Session; print("Session: " + session.id); ta = showText(""); er = nu(EditRecorder, +session); onUpdate(ta, r { er.update(ta.getText()) }); onCaret(ta, r { er.updateCaret(ta.getCaretPosition()) }); }