Skip to content

Commit

Permalink
continued - reimplement cell editing abstraction. Now TextEditor `<te…
Browse files Browse the repository at this point in the history
…xtarea>` is decoupled from cell selection and copy/paste keyboard handling; upgrade Bootstrap Typeahead to v2.3.0
  • Loading branch information
warpech committed Feb 25, 2013
1 parent 1eb01bd commit f2b412f
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Bugfix:
- scrolls to top of table on any key press if the top is not on the screen ([#348](https://github.com/warpech/jquery-handsontable/issues/348))
- cell editor was using a wrong cell value if column order was manually changed ([#367](https://github.com/warpech/jquery-handsontable/issues/367))

Other:
- reimplement cell editing abstraction. Now TextEditor `<textarea>` is decoupled from cell selection and copy/paste keyboard handling
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.handsontable.full.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Mon Feb 25 2013 19:56:16 GMT+0100 (Central European Standard Time)
* Date: Mon Feb 25 2013 20:14:15 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
37 changes: 17 additions & 20 deletions dist/jquery.handsontable.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Mon Feb 25 2013 19:56:16 GMT+0100 (Central European Standard Time)
* Date: Mon Feb 25 2013 20:14:15 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -1207,11 +1207,11 @@ Handsontable.Core = function (rootElement, settings) {
if (priv.settings.asyncRendering) {
clearTimeout(window.prepareFrame);
window.prepareFrame = setTimeout(function () {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}, 0);
}
else {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}
},

Expand Down Expand Up @@ -2159,7 +2159,7 @@ Handsontable.TableView = function (instance) {
columnHeaders: settings.colHeaders ? instance.getColHeader : null,
columnWidth: instance.getColWidth,
cellRenderer: function (row, column, TD) {
that.applyCellTypeMethod('renderer', TD, {row: row, col: column}, instance.getDataAtCell(row, column));
that.applyCellTypeMethod('renderer', TD, row, column);
},
selections: {
current: {
Expand Down Expand Up @@ -2295,10 +2295,10 @@ Handsontable.TableView.prototype.render = function () {
}
};

Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td, coords, extraParam) {
var prop = this.instance.colToProp(coords.col)
Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td, row, col) {
var prop = this.instance.colToProp(col)
, method
, cellProperties = this.instance.getCellMeta(coords.row, coords.col);
, cellProperties = this.instance.getCellMeta(row, col);

if (typeof cellProperties.type === 'string') {
switch (cellProperties.type) {
Expand All @@ -2318,7 +2318,7 @@ Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td,
if (typeof method !== "function") {
method = Handsontable.TextCell[methodName];
}
return method(this.instance, td, coords.row, coords.col, prop, extraParam, cellProperties);
return method(this.instance, td, row, col, prop, this.instance.getDataAtCell(row, col), cellProperties);
};

/**
Expand Down Expand Up @@ -2770,9 +2770,7 @@ HandsontableTextEditorClass.prototype.beginEditing = function (row, col, prop, u
}

if (useOriginalValue) {
var original = this.instance.getDataAtCell(row, prop);
original = Handsontable.helper.stringify(original) + (suffix || '');
this.TEXTAREA[0].value = original;
this.TEXTAREA[0].value = Handsontable.helper.stringify(this.originalValue) + (suffix || '');
}
else {
this.TEXTAREA[0].value = '';
Expand Down Expand Up @@ -2876,7 +2874,6 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
this.isCellEdited = false;
var val;
if (isCancelled) {

val = [
[this.originalValue]
];
Expand Down Expand Up @@ -2911,18 +2908,18 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} that.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.TextEditor = function (instance, td, row, col, prop, ___unused___, cellProperties) {
Handsontable.TextEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (!instance.textEditor) {
instance.textEditor = new HandsontableTextEditorClass(instance);
}

instance.textEditor.bindEvents();

instance.textEditor.isCellEdited = false;
instance.textEditor.originalValue = instance.getDataAtCell(row, prop);
instance.textEditor.originalValue = value;

instance.$table.on('keydown.editor', function (event) {
var ctrlDown = (event.ctrlKey || event.metaKey) && !event.altKey; //catch CTRL but not right ALT (which in some systems triggers ALT+CTRL)
Expand Down Expand Up @@ -3075,10 +3072,10 @@ HandsontableAutocompleteEditorClass.prototype.isMenuExpanded = function () {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} instance.autocompleteEditor.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, value, cellProperties) {
var i
, j;

Expand All @@ -3089,7 +3086,7 @@ Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unus
instance.autocompleteEditor.bindEvents();

instance.autocompleteEditor.isCellEdited = false;
instance.autocompleteEditor.originalValue = instance.getDataAtCell(row, prop);
instance.autocompleteEditor.originalValue = value;

var typeahead = instance.autocompleteEditor.typeahead;

Expand Down Expand Up @@ -3197,10 +3194,10 @@ function toggleCheckboxCell(instance, row, prop, cellProperties) {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} keyboardProxy jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (typeof cellProperties === "undefined") {
cellProperties = {};
}
Expand Down
2 changes: 1 addition & 1 deletion jquery.handsontable.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Mon Feb 25 2013 19:56:16 GMT+0100 (Central European Standard Time)
* Date: Mon Feb 25 2013 20:14:15 GMT+0100 (Central European Standard Time)
*/

.handsontable {
Expand Down
37 changes: 17 additions & 20 deletions jquery.handsontable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
* http://handsontable.com/
*
* Date: Mon Feb 25 2013 19:56:16 GMT+0100 (Central European Standard Time)
* Date: Mon Feb 25 2013 20:14:15 GMT+0100 (Central European Standard Time)
*/
/*jslint white: true, browser: true, plusplus: true, indent: 4, maxerr: 50 */

Expand Down Expand Up @@ -1207,11 +1207,11 @@ Handsontable.Core = function (rootElement, settings) {
if (priv.settings.asyncRendering) {
clearTimeout(window.prepareFrame);
window.prepareFrame = setTimeout(function () {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}, 0);
}
else {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}
},

Expand Down Expand Up @@ -2159,7 +2159,7 @@ Handsontable.TableView = function (instance) {
columnHeaders: settings.colHeaders ? instance.getColHeader : null,
columnWidth: instance.getColWidth,
cellRenderer: function (row, column, TD) {
that.applyCellTypeMethod('renderer', TD, {row: row, col: column}, instance.getDataAtCell(row, column));
that.applyCellTypeMethod('renderer', TD, row, column);
},
selections: {
current: {
Expand Down Expand Up @@ -2295,10 +2295,10 @@ Handsontable.TableView.prototype.render = function () {
}
};

Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td, coords, extraParam) {
var prop = this.instance.colToProp(coords.col)
Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td, row, col) {
var prop = this.instance.colToProp(col)
, method
, cellProperties = this.instance.getCellMeta(coords.row, coords.col);
, cellProperties = this.instance.getCellMeta(row, col);

if (typeof cellProperties.type === 'string') {
switch (cellProperties.type) {
Expand All @@ -2318,7 +2318,7 @@ Handsontable.TableView.prototype.applyCellTypeMethod = function (methodName, td,
if (typeof method !== "function") {
method = Handsontable.TextCell[methodName];
}
return method(this.instance, td, coords.row, coords.col, prop, extraParam, cellProperties);
return method(this.instance, td, row, col, prop, this.instance.getDataAtCell(row, col), cellProperties);
};

/**
Expand Down Expand Up @@ -2770,9 +2770,7 @@ HandsontableTextEditorClass.prototype.beginEditing = function (row, col, prop, u
}

if (useOriginalValue) {
var original = this.instance.getDataAtCell(row, prop);
original = Handsontable.helper.stringify(original) + (suffix || '');
this.TEXTAREA[0].value = original;
this.TEXTAREA[0].value = Handsontable.helper.stringify(this.originalValue) + (suffix || '');
}
else {
this.TEXTAREA[0].value = '';
Expand Down Expand Up @@ -2876,7 +2874,6 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
this.isCellEdited = false;
var val;
if (isCancelled) {

val = [
[this.originalValue]
];
Expand Down Expand Up @@ -2911,18 +2908,18 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} that.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.TextEditor = function (instance, td, row, col, prop, ___unused___, cellProperties) {
Handsontable.TextEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (!instance.textEditor) {
instance.textEditor = new HandsontableTextEditorClass(instance);
}

instance.textEditor.bindEvents();

instance.textEditor.isCellEdited = false;
instance.textEditor.originalValue = instance.getDataAtCell(row, prop);
instance.textEditor.originalValue = value;

instance.$table.on('keydown.editor', function (event) {
var ctrlDown = (event.ctrlKey || event.metaKey) && !event.altKey; //catch CTRL but not right ALT (which in some systems triggers ALT+CTRL)
Expand Down Expand Up @@ -3075,10 +3072,10 @@ HandsontableAutocompleteEditorClass.prototype.isMenuExpanded = function () {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} instance.autocompleteEditor.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, value, cellProperties) {
var i
, j;

Expand All @@ -3089,7 +3086,7 @@ Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unus
instance.autocompleteEditor.bindEvents();

instance.autocompleteEditor.isCellEdited = false;
instance.autocompleteEditor.originalValue = instance.getDataAtCell(row, prop);
instance.autocompleteEditor.originalValue = value;

var typeahead = instance.autocompleteEditor.typeahead;

Expand Down Expand Up @@ -3197,10 +3194,10 @@ function toggleCheckboxCell(instance, row, prop, cellProperties) {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} keyboardProxy jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (typeof cellProperties === "undefined") {
cellProperties = {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1188,11 +1188,11 @@ Handsontable.Core = function (rootElement, settings) {
if (priv.settings.asyncRendering) {
clearTimeout(window.prepareFrame);
window.prepareFrame = setTimeout(function () {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}, 0);
}
else {
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.coords()/*, priv.editProxy*/);
priv.editorDestroyer = self.view.applyCellTypeMethod('editor', self.view.getCellAtCoords(priv.selStart.coords()), priv.selStart.row(), priv.selStart.col());
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/editors/autocompleteEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ HandsontableAutocompleteEditorClass.prototype.isMenuExpanded = function () {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} instance.autocompleteEditor.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, value, cellProperties) {
var i
, j;

Expand All @@ -125,7 +125,7 @@ Handsontable.AutocompleteEditor = function (instance, td, row, col, prop, __unus
instance.autocompleteEditor.bindEvents();

instance.autocompleteEditor.isCellEdited = false;
instance.autocompleteEditor.originalValue = instance.getDataAtCell(row, prop);
instance.autocompleteEditor.originalValue = value;

var typeahead = instance.autocompleteEditor.typeahead;

Expand Down
4 changes: 2 additions & 2 deletions src/editors/checkboxEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function toggleCheckboxCell(instance, row, prop, cellProperties) {
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} keyboardProxy jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, __unused_, cellProperties) {
Handsontable.CheckboxEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (typeof cellProperties === "undefined") {
cellProperties = {};
}
Expand Down
11 changes: 4 additions & 7 deletions src/editors/textEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ HandsontableTextEditorClass.prototype.beginEditing = function (row, col, prop, u
}

if (useOriginalValue) {
var original = this.instance.getDataAtCell(row, prop);
original = Handsontable.helper.stringify(original) + (suffix || '');
this.TEXTAREA[0].value = original;
this.TEXTAREA[0].value = Handsontable.helper.stringify(this.originalValue) + (suffix || '');
}
else {
this.TEXTAREA[0].value = '';
Expand Down Expand Up @@ -280,7 +278,6 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
this.isCellEdited = false;
var val;
if (isCancelled) {

val = [
[this.originalValue]
];
Expand Down Expand Up @@ -315,18 +312,18 @@ HandsontableTextEditorClass.prototype.finishEditing = function (isCancelled, ctr
* @param {Number} row
* @param {Number} col
* @param {String|Number} prop Row object property name
* @param {Object} that.TEXTAREA jQuery element of keyboard proxy that contains current editing value
* @param value Original value (remember to escape unsafe HTML before inserting to DOM!)
* @param {Object} cellProperties Cell properites (shared by cell renderer and editor)
*/
Handsontable.TextEditor = function (instance, td, row, col, prop, ___unused___, cellProperties) {
Handsontable.TextEditor = function (instance, td, row, col, prop, value, cellProperties) {
if (!instance.textEditor) {
instance.textEditor = new HandsontableTextEditorClass(instance);
}

instance.textEditor.bindEvents();

instance.textEditor.isCellEdited = false;
instance.textEditor.originalValue = instance.getDataAtCell(row, prop);
instance.textEditor.originalValue = value;

instance.$table.on('keydown.editor', function (event) {
var ctrlDown = (event.ctrlKey || event.metaKey) && !event.altKey; //catch CTRL but not right ALT (which in some systems triggers ALT+CTRL)
Expand Down
Loading

0 comments on commit f2b412f

Please sign in to comment.