1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Improve autocomplete behavior when typing ordered lists

Summary:
Ref T10163.

  - If a user types an autocomplete character ("@" or "#") and then a space, deactivate immediately (probably an ordered list).
  - If a user types an autocomplete character indented on a line with no other prior text, don't activate (probably an ordered list or code block).

Test Plan:
Typed:

  - `# `, saw immediate deactivation.
  - ` #`, saw no activation in the first place.
  - `#x`, saw activation.
  - `asdf #x`, saw activation.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10163

Differential Revision: https://secure.phabricator.com/D15033
This commit is contained in:
epriestley 2016-01-15 11:10:38 -08:00
parent 7f19216e44
commit 2d495e9701
2 changed files with 20 additions and 3 deletions

View file

@ -507,7 +507,7 @@ return array(
'rsrc/js/phui/behavior-phui-object-box-tabs.js' => '2bfa2836',
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
'rsrc/js/phuix/PHUIXActionView.js' => '8cf6d262',
'rsrc/js/phuix/PHUIXAutocomplete.js' => '3d6e37cc',
'rsrc/js/phuix/PHUIXAutocomplete.js' => '3dfff01f',
'rsrc/js/phuix/PHUIXDropdownMenu.js' => 'bd4c8dca',
'rsrc/js/phuix/PHUIXFormControl.js' => '8fba1997',
'rsrc/js/phuix/PHUIXIconView.js' => 'bff6884b',
@ -836,7 +836,7 @@ return array(
'phui-workpanel-view-css' => 'adec7699',
'phuix-action-list-view' => 'b5c256b8',
'phuix-action-view' => '8cf6d262',
'phuix-autocomplete' => '3d6e37cc',
'phuix-autocomplete' => '3dfff01f',
'phuix-dropdown-menu' => 'bd4c8dca',
'phuix-form-control-view' => '8fba1997',
'phuix-icon-view' => 'bff6884b',
@ -1080,7 +1080,7 @@ return array(
'javelin-util',
'javelin-uri',
),
'3d6e37cc' => array(
'3dfff01f' => array(
'javelin-install',
'javelin-dom',
'phuix-icon-view',

View file

@ -119,6 +119,16 @@ JX.install('PHUIXAutocomplete', {
return;
}
// Get all the text on the current line. If the line begins with
// whitespace, don't activate: the user is probably typing code or a
// numbered list.
var line = area.value.substring(0, head);
line = line.split('\n');
line = line[line.length - 1];
if (line.match(/^\s+/)) {
return;
}
this._cursorHead = head;
this._cursorTail = range.end;
this._pixelHead = JX.TextAreaUtils.getPixelDimensions(
@ -370,6 +380,13 @@ JX.install('PHUIXAutocomplete', {
var x = this._pixelHead.start.x;
var y = Math.max(this._pixelHead.end.y, pixels.end.y) + 24;
// If the first character after the trigger is a space, just deactivate
// immediately. This occurs if a user types a numbered list using "#".
if (text.length && text[0] == ' ') {
this._deactivate();
return;
}
var trim = this._trim(text);
this._datasource.didChange(trim);