diff --git a/tools/test-js-with-node b/tools/test-js-with-node index a7e45e8125..05cf5405d7 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -67,7 +67,7 @@ EXEMPT_FILES = make_set( "web/src/compose_fade.js", "web/src/compose_recipient.js", "web/src/compose_state.js", - "web/src/compose_textarea.js", + "web/src/compose_textarea.ts", "web/src/compose_ui.js", "web/src/compose_validate.js", "web/src/composebox_typeahead.js", diff --git a/web/src/compose_textarea.js b/web/src/compose_textarea.ts similarity index 83% rename from web/src/compose_textarea.js rename to web/src/compose_textarea.ts index f89c2fcfd8..6b33641f08 100644 --- a/web/src/compose_textarea.js +++ b/web/src/compose_textarea.ts @@ -4,7 +4,7 @@ import $ from "jquery"; // shift-tab back in (see hotkey.js). let saved_compose_cursor = 0; -function set_compose_textarea_handlers() { +function set_compose_textarea_handlers(): void { $("#compose-textarea").on("blur", function () { saved_compose_cursor = $(this).caret(); }); @@ -16,10 +16,10 @@ function set_compose_textarea_handlers() { }); } -export function restore_compose_cursor() { +export function restore_compose_cursor(): void { $("#compose-textarea").trigger("focus").caret(saved_compose_cursor); } -export function initialize() { +export function initialize(): void { set_compose_textarea_handlers(); } diff --git a/web/src/global.d.ts b/web/src/global.d.ts index 7e38aacdf6..fb57733d30 100644 --- a/web/src/global.d.ts +++ b/web/src/global.d.ts @@ -5,10 +5,26 @@ declare let zulip_test: any; // eslint-disable-line @typescript-eslint/no-explicit-any +type JQueryCaretRange = { + start: number; + end: number; + length: number; + text: string; +}; + // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface JQuery { expectOne(): JQuery; tab(action?: string): this; // From web/third/bootstrap + + // Types for jquery-caret-plugin + caret(): number; + caret(arg: number | string): this; + range(): JQueryCaretRange; + range(start: number, end?: number): this; + range(text: string): this; + selectAll(): this; + deselectAll(): this; } declare const ZULIP_VERSION: string;