Skip to content

Commit a4f0dc5

Browse files
committed
autocomplete: Add support for composing "silent mentions".
Add markdown syntax for "silent mentions", which happens when a user starts their mention with "@_". Add empty "silent" class for future styling changes.
1 parent f6b9f03 commit a4f0dc5

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

Diff for: src/autocomplete/__tests__/getAutocompleteFilter-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ describe('getAutocompleteFilter', () => {
1111
selection = { start: 1, end: 1 };
1212
expect(getAutocompleteFilter('@', selection)).toEqual({ filter: '', lastWordPrefix: '@' });
1313

14+
selection = { start: 2, end: 2 };
15+
expect(getAutocompleteFilter('@_', selection)).toEqual({ filter: '', lastWordPrefix: '@' });
16+
17+
selection = { start: 4, end: 4 };
18+
expect(getAutocompleteFilter('@_ab', selection)).toEqual({ filter: 'ab', lastWordPrefix: '@' });
19+
20+
selection = { start: 7, end: 7 };
21+
expect(getAutocompleteFilter('@_ab cd', selection)).toEqual({
22+
filter: 'ab cd',
23+
lastWordPrefix: '@',
24+
});
25+
1426
selection = { start: 3, end: 3 };
1527
expect(getAutocompleteFilter('@ab', selection)).toEqual({ filter: 'ab', lastWordPrefix: '@' });
1628

Diff for: src/autocomplete/__tests__/getAutocompletedText-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ describe('getAutocompletedText', () => {
3333
selection = { start: 3, end: 3 };
3434
expect(getAutocompletedText(':abSome text', 'abcd', selection)).toEqual(':abcd: Some text');
3535
});
36+
37+
test('can autocomplete users (silently)', () => {
38+
selection = { start: 4, end: 4 };
39+
expect(getAutocompletedText('@_ab', '**abcd**', selection)).toEqual('@_**abcd** ');
40+
});
3641
});

Diff for: src/autocomplete/getAutocompleteFilter.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default (textWhole: string, selection: InputSelectionType) => {
2020
const lastWordPrefix: string = lastIndex !== -1 ? text[lastIndex] : '';
2121
const filter: string =
2222
text.length > lastIndex + 1 && !['\n', ' '].includes(text[lastIndex + 1])
23-
? text.substring(lastIndex + 1, text.length)
23+
? text.substring(
24+
lastIndex + 1 + (text[lastIndex] === '@' && text[lastIndex + 1] === '_'),
25+
text.length,
26+
)
2427
: '';
2528

2629
return { lastWordPrefix, filter };

Diff for: src/autocomplete/getAutocompletedText.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export default (textWhole: string, autocompleteText: string, selection: InputSel
1717
text.lastIndexOf('@'),
1818
);
1919

20-
const prefix = text[lastIndex] === ':' ? ':' : `${text[lastIndex]}`;
20+
let prefix = text[lastIndex] === ':' ? ':' : `${text[lastIndex]}`;
21+
if (text[lastIndex] === '@' && text[lastIndex + 1] === '_') {
22+
prefix += '_';
23+
}
2124
const suffix = text[lastIndex] === ':' ? ':' : '';
2225

2326
return `${text.substring(0, lastIndex)}${prefix}${autocompleteText}${suffix} ${remainder}`;

Diff for: src/webview/css/css.js

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ hr {
140140
padding: 0 .2em;
141141
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
142142
}
143+
.silent {
144+
}
143145
.header-wrapper {
144146
position: -webkit-sticky;
145147
position: sticky;

0 commit comments

Comments
 (0)