Skip to content

Commit ba98e10

Browse files
committed
Fix the bug that compare to clipboard is not working
* Give a default value ([]) if line range is not given
1 parent a772990 commit ba98e10

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

lib/selection-info-registry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SelectionInfoRegistry {
99
this._data[key] = {
1010
text: textInfo.text,
1111
fileName: textInfo.fileName,
12-
lineRanges: textInfo.lineRanges
12+
lineRanges: textInfo.lineRanges || []
1313
};
1414
}
1515

test/lib/selection-info-registry.test.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@ const SelectionInfoRegistry = require('../../lib/selection-info-registry');
33

44
suite('SelectionInfoRegistry', () => {
55

6-
test('it saves a given text selection information with a given key', () => {
6+
test('it saves selected text with a given key', () => {
77
const selectionInfoRegistry = new SelectionInfoRegistry();
8-
selectionInfoRegistry.set('KEY', {
9-
text: 'TEXT',
10-
fileName: 'FILE_NAME',
11-
lineRanges: 'LINE_RANGES',
12-
'..': '..'
13-
});
14-
expect(selectionInfoRegistry.get('KEY')).to.eql({
15-
text: 'TEXT',
16-
fileName: 'FILE_NAME',
17-
lineRanges: 'LINE_RANGES'
18-
});
8+
selectionInfoRegistry.set('KEY', {text: 'TEXT'});
9+
expect(selectionInfoRegistry.get('KEY').text).to.include('TEXT');
10+
});
11+
12+
test('it saves the file name of the selected text with a given key', () => {
13+
const selectionInfoRegistry = new SelectionInfoRegistry();
14+
selectionInfoRegistry.set('KEY', {fileName: 'FILE_NAME'});
15+
expect(selectionInfoRegistry.get('KEY').fileName).to.eql('FILE_NAME');
16+
});
17+
18+
test('it saves the line ranges of the selected text with a given key', () => {
19+
const selectionInfoRegistry = new SelectionInfoRegistry();
20+
selectionInfoRegistry.set('KEY', {lineRanges: 'LINE_RANGES'});
21+
expect(selectionInfoRegistry.get('KEY').lineRanges).to.eql('LINE_RANGES');
22+
});
23+
24+
test('it ignores other attributes given in text info', () => {
25+
const selectionInfoRegistry = new SelectionInfoRegistry();
26+
selectionInfoRegistry.set('KEY', {SOMETHING: '..'});
27+
expect(selectionInfoRegistry.get('KEY').SOMETHING).to.be.undefined;
28+
});
29+
30+
test('it sets an empty list for line ranges if they are not given', () => {
31+
const selectionInfoRegistry = new SelectionInfoRegistry();
32+
selectionInfoRegistry.set('KEY', {});
33+
expect(selectionInfoRegistry.get('KEY').lineRanges).to.eql([]);
1934
});
2035

2136
});

0 commit comments

Comments
 (0)