mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Add autocomplete for Phriction documents on "[[ ..." in Remarkup
Summary: Depends on D19107. Ref T13077. The underlying datasource may need some adjustment but this appears to work properly locally. Test Plan: Typed `[[ por` locally, was suggested "Porcupine Facts". Typed `[[ / ]]`, saw it render as a reference to the wiki root instead of the install root. Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19108
This commit is contained in:
parent
f82206a4d1
commit
8771b7d5c4
4 changed files with 45 additions and 11 deletions
|
@ -528,7 +528,7 @@ return array(
|
|||
'rsrc/js/phui/behavior-phui-tab-group.js' => '0a0b10e9',
|
||||
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
|
||||
'rsrc/js/phuix/PHUIXActionView.js' => '442efd08',
|
||||
'rsrc/js/phuix/PHUIXAutocomplete.js' => 'e0731603',
|
||||
'rsrc/js/phuix/PHUIXAutocomplete.js' => 'bb19ed2c',
|
||||
'rsrc/js/phuix/PHUIXButtonView.js' => '8a91e1ac',
|
||||
'rsrc/js/phuix/PHUIXDropdownMenu.js' => '04b2ae03',
|
||||
'rsrc/js/phuix/PHUIXExample.js' => '68af71ca',
|
||||
|
@ -881,7 +881,7 @@ return array(
|
|||
'phui-workpanel-view-css' => 'a3a63478',
|
||||
'phuix-action-list-view' => 'b5c256b8',
|
||||
'phuix-action-view' => '442efd08',
|
||||
'phuix-autocomplete' => 'e0731603',
|
||||
'phuix-autocomplete' => 'bb19ed2c',
|
||||
'phuix-button-view' => '8a91e1ac',
|
||||
'phuix-dropdown-menu' => '04b2ae03',
|
||||
'phuix-form-control-view' => '16ad6224',
|
||||
|
@ -1868,6 +1868,12 @@ return array(
|
|||
'javelin-uri',
|
||||
'phabricator-notification',
|
||||
),
|
||||
'bb19ed2c' => array(
|
||||
'javelin-install',
|
||||
'javelin-dom',
|
||||
'phuix-icon-view',
|
||||
'phabricator-prefab',
|
||||
),
|
||||
'bcaccd64' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-behavior-device',
|
||||
|
@ -2033,12 +2039,6 @@ return array(
|
|||
'javelin-typeahead-ondemand-source',
|
||||
'javelin-dom',
|
||||
),
|
||||
'e0731603' => array(
|
||||
'javelin-install',
|
||||
'javelin-dom',
|
||||
'phuix-icon-view',
|
||||
'phabricator-prefab',
|
||||
),
|
||||
'e1d25dfb' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-stratcom',
|
||||
|
|
|
@ -68,6 +68,7 @@ final class PhrictionDocumentDatasource
|
|||
$title = $content->getTitle();
|
||||
|
||||
$sprite = 'phabricator-search-icon phui-font-fa phui-icon-view fa-book';
|
||||
$autocomplete = '[[ '.$slug.' ]]';
|
||||
|
||||
$result = id(new PhabricatorTypeaheadResult())
|
||||
->setName($title)
|
||||
|
@ -77,6 +78,7 @@ final class PhrictionDocumentDatasource
|
|||
->setDisplayType($slug)
|
||||
->setPriorityType('wiki')
|
||||
->setImageSprite($sprite)
|
||||
->setAutocomplete($autocomplete)
|
||||
->setClosed($closed);
|
||||
|
||||
$results[] = $result;
|
||||
|
|
|
@ -72,6 +72,8 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
|
|||
'autocomplete' => 1,
|
||||
));
|
||||
|
||||
$phriction_datasource = new PhrictionDocumentDatasource();
|
||||
|
||||
Javelin::initBehavior(
|
||||
'phabricator-remarkup-assist',
|
||||
array(
|
||||
|
@ -118,6 +120,18 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
|
|||
'/',
|
||||
),
|
||||
),
|
||||
91 => array( // "["
|
||||
'datasourceURI' => $phriction_datasource->getDatasourceURI(),
|
||||
'headerIcon' => 'fa-book',
|
||||
'headerText' => pht('Find Document:'),
|
||||
'hintText' => $phriction_datasource->getPlaceholderText(),
|
||||
'cancel' => array(
|
||||
':', // Cancel on "http:" and similar.
|
||||
'|',
|
||||
']',
|
||||
),
|
||||
'prefix' => '^\\[*',
|
||||
),
|
||||
),
|
||||
));
|
||||
Javelin::initBehavior('phabricator-tooltips', array());
|
||||
|
|
|
@ -335,7 +335,9 @@ JX.install('PHUIXAutocomplete', {
|
|||
_getCancelCharacters: function() {
|
||||
// The "." character does not cancel because of projects named
|
||||
// "node.js" or "blog.mycompany.com".
|
||||
return ['#', '@', ',', '!', '?', '{', '}'];
|
||||
var defaults = ['#', '@', ',', '!', '?', '{', '}'];
|
||||
|
||||
return this._map[this._active].cancel || defaults;
|
||||
},
|
||||
|
||||
_getTerminators: function() {
|
||||
|
@ -498,8 +500,6 @@ JX.install('PHUIXAutocomplete', {
|
|||
this._cursorHead,
|
||||
this._cursorTail);
|
||||
|
||||
this._value = text;
|
||||
|
||||
var pixels = JX.TextAreaUtils.getPixelDimensions(
|
||||
area,
|
||||
range.start,
|
||||
|
@ -517,6 +517,24 @@ JX.install('PHUIXAutocomplete', {
|
|||
|
||||
var trim = this._trim(text);
|
||||
|
||||
// If this rule has a prefix pattern, like the "[[ document ]]" rule,
|
||||
// require it match and throw it away before we begin suggesting
|
||||
// results. The autocomplete remains active, it's just dormant until
|
||||
// the user gives us more to work with.
|
||||
var prefix = this._map[this._active].prefix;
|
||||
if (prefix) {
|
||||
var pattern = new RegExp(prefix);
|
||||
if (!trim.match(pattern)) {
|
||||
return;
|
||||
}
|
||||
trim = trim.replace(pattern, '');
|
||||
trim = trim.trim();
|
||||
}
|
||||
|
||||
// Store the current value now that we've finished mutating the text.
|
||||
// This needs to match what we pass to the typeahead datasource.
|
||||
this._value = trim;
|
||||
|
||||
// Deactivate immediately if a user types a character that we are
|
||||
// reasonably sure means they don't want to use the autocomplete. For
|
||||
// example, "##" is almost certainly a header or monospaced text, not
|
||||
|
|
Loading…
Reference in a new issue