Skip to content

Commit

Permalink
Merge pull request #40 from FieldVal/develop
Browse files Browse the repository at this point in the history
Switched tab insertion method to document.executeCommand
  • Loading branch information
MarcusLongmuir committed Apr 9, 2015
2 parents 03f6a69 + 446f5fc commit bb12749
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fieldval-ui",
"version": "0.4.3",
"version": "0.4.4",
"main": "fieldval-ui.js",
"ignore": [
"bower_components",
Expand Down
12 changes: 2 additions & 10 deletions fieldval-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,9 @@ function FVTextField(name, options) {
}
}

if(field.consume_tabs && e.keyCode===9) {
if(field.input_type==="textarea" && field.consume_tabs && e.keyCode===9) {
e.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;

// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end));

// put caret at right position again
$(this).get(0).selectionStart =
$(this).get(0).selectionEnd = start + 1;
document.execCommand("insertText", false, "\t");
}
})
.on("keyup paste cut",function(){
Expand Down
4 changes: 2 additions & 2 deletions fieldval-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fieldval-ui",
"version": "0.4.3",
"version": "0.4.4",
"description": "fieldval-ui",
"main": "fieldval-ui.js",
"scripts": {
Expand Down
12 changes: 2 additions & 10 deletions src/FVField/FVTextField/FVTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,9 @@ function FVTextField(name, options) {
}
}

if(field.consume_tabs && e.keyCode===9) {
if(field.input_type==="textarea" && field.consume_tabs && e.keyCode===9) {
e.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;

// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end));

// put caret at right position again
$(this).get(0).selectionStart =
$(this).get(0).selectionEnd = start + 1;
document.execCommand("insertText", false, "\t");
}
})
.on("keyup paste cut",function(){
Expand Down

0 comments on commit bb12749

Please sign in to comment.