Skip to content

Commit 5ef6543

Browse files
committed
feat: Notify native host on autocomplete trigger
Enable the host to respond to autocomplete events.
1 parent 74af9a8 commit 5ef6543

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/components/editor/use-at-autocompleter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import { addFilter, removeFilter } from '@wordpress/hooks';
55
import { useEffect } from '@wordpress/element';
66

7-
/*
7+
/**
88
* Internal dependencies
99
*/
10-
import { info } from '../../utils/logger';
10+
import { onAutocompleterTriggered } from '../../utils/bridge';
1111

1212
/**
1313
* Adds a filter for the Autocomplete completers to show an alert when @ is typed.
@@ -48,7 +48,7 @@ function addAtSymbolCompleter( completers = [] ) {
4848
name: 'at-symbol',
4949
triggerPrefix: '@',
5050
options: () => {
51-
info( 'You typed an @ symbol!' );
51+
onAutocompleterTriggered( 'at-symbol' );
5252
// Return empty array since we're not providing actual completion options
5353
return [];
5454
},

src/components/editor/use-plus-autocompleter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import { addFilter, removeFilter } from '@wordpress/hooks';
55
import { useEffect } from '@wordpress/element';
66

7-
/*
7+
/**
88
* Internal dependencies
99
*/
10-
import { info } from '../../utils/logger';
10+
import { onAutocompleterTriggered } from '../../utils/bridge';
1111

1212
/**
1313
* Adds a filter for the Autocomplete completers to show an alert when + is typed.
@@ -42,7 +42,7 @@ function addPlusSymbolCompleter( completers = [] ) {
4242
name: 'plus-symbol',
4343
triggerPrefix: '+',
4444
options: () => {
45-
info( 'You typed a + symbol!' );
45+
onAutocompleterTriggered( 'plus-symbol' );
4646
// Return empty array since we're not providing actual completion options
4747
return [];
4848
},

src/utils/bridge.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ export function openMediaLibrary( config ) {
121121
}
122122
}
123123

124+
/**
125+
* Notifies the native host that an autocompleter was triggered.
126+
*
127+
* @param {string} type The type of autocompleter that was triggered (e.g. 'at-symbol', 'plus-symbol').
128+
*
129+
* @return {void}
130+
*/
131+
export function onAutocompleterTriggered( type ) {
132+
dispatchToBridge( 'onAutocompleterTriggered', { type } );
133+
}
134+
124135
/**
125136
* @typedef GBKitConfig
126137
*

0 commit comments

Comments
 (0)