From 538b16c2350b75eccdefc249de6c58d851571c42 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 9 May 2012 16:12:42 +0200 Subject: [PATCH] [ADD] backspace from within an empty input should remove the preceding facet, if any bzr revid: xmo@openerp.com-20120509141242-5l75w08ruv4r8xtc --- addons/web/static/src/js/search.js | 31 +++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index b5e5f8f3f1f..198740f4a97 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -125,7 +125,6 @@ function assert(condition, message) { my.InputView = instance.web.Widget.extend({ template: 'SearchView.InputView', start: function () { - var self = this; var p = this._super.apply(this, arguments); this.$element.on('focus', this.proxy('onFocus')); this.$element.on('blur', this.proxy('onBlur')); @@ -181,6 +180,18 @@ my.InputView = instance.web.Widget.extend({ e.preventDefault(); break; + // FIXME: may forget content if non-empty but caret at index 0, ok? + case $.ui.keyCode.BACKSPACE: + sel = this.getSelection(); + if (sel.start === 0 && sel.start === sel.end) { + e.preventDefault(); + var preceding = this.getParent().siblingSubview(this, -1); + if (preceding && (preceding instanceof my.FacetView)) { + preceding.model.destroy(); + } + } + break; + // let left/right events propagate to view if caret is at input border // and not a selection case $.ui.keyCode.LEFT: @@ -376,22 +387,24 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea return subview.$element[0] === subview_root; }); }, - focusRelative: function (subview, direction) { + siblingSubview: function (subview, direction, wrap_around) { var index = _(this.input_subviews).indexOf(subview) + direction; - if (index < 0) { + if (wrap_around && index < 0) { index = this.input_subviews.length - 1; - } else if (index >= this.input_subviews.length) { + } else if (wrap_around && index >= this.input_subviews.length) { index = 0; } - this.input_subviews[index].$element.focus(); + return this.input_subviews[index]; }, focusPreceding: function (subview_root) { - return this.focusRelative( - this.subviewForRoot(subview_root), -1); + return this.siblingSubview( + this.subviewForRoot(subview_root), -1, true) + .$element.focus(); }, focusFollowing: function (subview_root) { - return this.focusRelative( - this.subviewForRoot(subview_root), +1); + return this.siblingSubview( + this.subviewForRoot(subview_root), +1, true) + .$element.focus(); }, /**