Skip to content

Commit 1ca1bed

Browse files
committed
Works with delimiters
1 parent f193267 commit 1ca1bed

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

build/smart-number-inputs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
3838

3939
var ARROW_UP = 38;
4040
var ARROW_DOWN = 40;
41-
var WHITESPACE = /(\s+)/;
41+
var DELIMITER = /([^\-\w0-9]+)/;
4242

4343
var eventHandler = function eventHandler(event) {
4444
if (event.which !== ARROW_UP && event.which !== ARROW_DOWN) return;
@@ -69,7 +69,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
6969
};
7070

7171
var modify = function modify(value, start, end, addition) {
72-
var segments = value.split(WHITESPACE);
72+
var segments = value.split(DELIMITER);
7373

7474
// Will transform selection to encapsulate affected segments
7575
var newStart = null;
@@ -81,7 +81,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
8181
originalValue = segments[i];
8282
character += originalValue.length;
8383

84-
if (originalValue.match(WHITESPACE)) continue;
84+
if (originalValue.match(DELIMITER)) continue;
8585

8686
if (character >= start) {
8787
if (newStart === null) newStart = character - originalValue.length;

build/smart-number-inputs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
const ARROW_UP = 38;
2121
const ARROW_DOWN = 40;
22-
const WHITESPACE = /(\s+)/;
22+
const DELIMITER = /([^\-\w0-9]+)/;
2323

2424
const eventHandler = event => {
2525
if(event.which !== ARROW_UP && event.which !== ARROW_DOWN) return;
@@ -50,8 +50,8 @@
5050
};
5151

5252
const modify = (value, start, end, addition) => {
53-
const segments = value.split(WHITESPACE);
54-
53+
const segments = value.split(DELIMITER);
54+
5555
// Will transform selection to encapsulate affected segments
5656
let newStart = null;
5757
let newEnd = null;
@@ -62,7 +62,7 @@
6262
originalValue = segments[i];
6363
character += originalValue.length;
6464

65-
if(originalValue.match(WHITESPACE)) continue;
65+
if(originalValue.match(DELIMITER)) continue;
6666

6767
if(character >= start) {
6868
if(newStart === null) newStart = character - originalValue.length;

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ test('value', t => {
5353
t.equal(modify('foo', 1, 1, 1).value, 'foo');
5454
t.equal(modify('foo', 2, 2, 1).value, 'foo');
5555

56+
t.equal(modify('10:15', 0, 0, 1).value, '11:15');
57+
t.equal(modify('10:15', 1, 1, 1).value, '11:15');
58+
t.equal(modify('10:15', 2, 2, 1).value, '11:15');
59+
t.equal(modify('10:15', 3, 3, 1).value, '10:16');
60+
t.equal(modify('10:15', 4, 4, 1).value, '10:16');
61+
t.equal(modify('10:15', 5, 5, 1).value, '10:16');
62+
t.equal(modify('10:15', 0, 5, 1).value, '11:16');
63+
t.equal(modify('10:15', 1, 3, 1).value, '11:16');
64+
5665
t.end();
5766
});
5867

@@ -75,5 +84,14 @@ test('selection', t => {
7584
t.equal(modify('20 -1 20', 3, 5, 1).start, 3);
7685
t.equal(modify('20 -1 20', 3, 5, 1).end, 4);
7786

87+
t.equal(modify('10:15', 1, 1, 1).start, 0);
88+
t.equal(modify('10:15', 1, 1, 1).end, 2);
89+
90+
t.equal(modify('10:15', 3, 3, 1).start, 3);
91+
t.equal(modify('10:15', 3, 3, 1).end, 5);
92+
93+
t.equal(modify('10:15', 1, 3, 1).start, 0);
94+
t.equal(modify('10:15', 1, 3, 1).end, 5);
95+
7896
t.end();
7997
});

0 commit comments

Comments
 (0)