mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
compose: Trigger language typeahead on using code formatting button.
To increase the discoverability of the possibility of specifying the language for a code block, we trigger the language typeahead when code syntax is added using the code formatting button. A blank option is shown preselected in the typeahead, so that pressing enter will not mistakenly add a language to the code block. We only trigger the typeahead on empty opening fences when added by the button, by setting a state variable to true when adding the syntax using the button, checking for this state when sourcing languages for the code typeahead, and then resetting the state variable to false. Fixes: #29150.
This commit is contained in:
@@ -46,8 +46,13 @@ type SelectedLinesSections = {
|
||||
|
||||
export let compose_spinner_visible = false;
|
||||
export let shift_pressed = false; // true or false
|
||||
export let code_formatting_button_triggered = false; // true or false
|
||||
let full_size_status = false; // true or false
|
||||
|
||||
export function set_code_formatting_button_triggered(value: boolean): void {
|
||||
code_formatting_button_triggered = value;
|
||||
}
|
||||
|
||||
// Some functions to handle the full size status explicitly
|
||||
export function set_full_size(is_full: boolean): void {
|
||||
full_size_status = is_full;
|
||||
@@ -1011,7 +1016,15 @@ export function format_text(
|
||||
if (range.end < text.length && text[range.end] !== "\n") {
|
||||
block_code_syntax_end = block_code_syntax_end + "\n";
|
||||
}
|
||||
format(block_code_syntax_start, block_code_syntax_end);
|
||||
const added_fence = format(block_code_syntax_start, block_code_syntax_end);
|
||||
if (added_fence) {
|
||||
const cursor_after_opening_fence =
|
||||
range.start + block_code_syntax_start.length - 1;
|
||||
field.setSelectionRange(cursor_after_opening_fence, cursor_after_opening_fence);
|
||||
set_code_formatting_button_triggered(true);
|
||||
// Trigger typeahead lookup with a click.
|
||||
field.click();
|
||||
}
|
||||
} else {
|
||||
format(inline_code_syntax);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user