!7

cmodule DiffTwoTexts {
  S text1, text2;
  S diff;
  switchable bool trim = true;

  visual centerAndSouth(hgrid(
    withTitle("Text A (-)", dm_textArea text1()),
    withTitle("Diff", withMargin(wrap(d = new JTextArea))),
    withTitle("Text B (+)", dm_textArea text2())),
    centeredLine(setToolTip("Also ignores empty lines", dm_checkBox("Ignore Indent", 'trim))));
    
  start {
    dm_watchFields(ll("a", "b", "trim"), r doDiff);
  }

  void doDiff enter {
    setField(diff := unidiff(preprocess(text1), preprocess(text2)));
  }

  S preprocess(S s) {
    if (isChecked(trim)) s = fullTrim(s);
    ret s;
  }
}