void edit_select_rep::selection_cut (string key) { if (inside_active_graphics ()) { if (key != "none") { tree t= as_tree (eval ("(graphics-cut)")); selection_set (key, t); } } else if (selection_active_any ()) { path p1, p2; if (selection_active_table ()) { p1= start_p; p2= end_p; if(key != "none") { tree sel= selection_get (); selection_set (key, sel); } } else { selection_get (p1, p2); go_to (p2); if (p2 == p1) return; if (key != "none") { tree sel= selection_compute (et, p1, p2); selection_set (key, simplify_correct (sel)); } } cut (p1, p2); } }
tree selection_compute (tree t, path start, path end) { int i1= start->item; int i2= end->item; path p1= start->next; path p2= end->next; if (is_nil (p1) || is_nil (p2)) { if (start == path (right_index (t))) return ""; if (end == path (0)) return ""; if (start == end) return ""; if (is_nil (p1) && is_nil (p2)) { if (is_compound (t)) return copy (t); if (i1>=i2) return ""; return t->label (i1, i2); } if (is_compound (t) && (!is_format (t))) return copy (t); if (is_nil (p1)) { i1= 0; p1= (start->item==0? 0: right_index (t[i1])); } if (is_nil (p2)) { i2= N(t)-1; p2= (end->item==0? 0: right_index (t[i2])); } } if (i1==i2) return selection_compute (t[i1], p1, p2); if (is_compound (t) && (!is_format (t))) return copy (t); int i; tree r (t, i2-i1+1); r[0] = selection_compute (t[i1], p1, path (right_index (t[i1]))); r[N(r)-1]= selection_compute (t[i2], path (0), p2); for (i=1; i<N(r)-1; i++) r[i]= copy (t[i+i1]); return r; }
tree edit_select_rep::selection_get () { if (!selection_active_any ()) return ""; if (selection_active_table ()) { int row1, col1, row2, col2; path fp= selection_get_subtable (row1, col1, row2, col2); return table_get_subtable (fp, row1, col1, row2, col2); } else { path start, end; // cout << "Selecting...\n"; selection_get (start, end); // cout << "Between paths: " << start << " and " << end << "\n"; tree t= selection_compute (et, start, end); // cout << "Selection : " << t << "\n"; return simplify_correct (t); } }