From c503c6d508e3707be0bfe52cea83b7fb3f77d746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 30 May 2015 09:45:25 +0200 Subject: [PATCH] Better management of row selection and switch Use dblclick to switch row instead of double selection. Switch row on tree with none selection like the menu as dblclick doesn't work on touchscreen. review7191002 --- src/view.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/view.js b/src/view.js index a8e3143cc6..17b9ee32b3 100644 --- a/src/view.js +++ b/src/view.js @@ -549,6 +549,7 @@ })); td.one('click', {column: i, td: td}, this.select_row.bind(this)); + td.dblclick(this.switch_row.bind(this)); var widgets = this.build_widgets(); var table = widgets[0]; var row = widgets[1]; @@ -733,22 +734,29 @@ this.record.load(this.children_field).done( add_children.bind(this)); }, + switch_row: function() { + if (window.getSelection) { + if (window.getSelection().empty) { // Chrome + window.getSelection().empty(); + } else if (window.getSelection().removeAllRanges) { // Firefox + window.getSelection().removeAllRanges(); + } + } else if (document.selection) { // IE? + document.selection.empty(); + } + this.tree.switch_(this.path); + }, select_row: function(event_) { if (this.tree.selection_mode == Sao.common.SELECTION_NONE) { this.tree.select_changed(this.record); - this.tree.switch_(this.path); + this.switch_row(); } else { - if (!event_.ctrlKey) { + if (!event_.ctrlKey && + this.tree.selection_mode == + Sao.common.SELECTION_SINGLE) { this.tree.rows.forEach(function(row) { - if (row != this) { - row.set_selection(false); - } + row.set_selection(false); }.bind(this)); - this.selection_changed(); - if (this.is_selected()) { - this.tree.switch_(this.path); - return; - } } this.set_selection(!this.is_selected()); this.selection_changed();