diff --git a/packages/editor/CodeMirror/utils/overwriteModeExtension.test.ts b/packages/editor/CodeMirror/utils/overwriteModeExtension.test.ts index 2be4212a5ce..8bf019c37af 100644 --- a/packages/editor/CodeMirror/utils/overwriteModeExtension.test.ts +++ b/packages/editor/CodeMirror/utils/overwriteModeExtension.test.ts @@ -3,6 +3,7 @@ import createTestEditor from '../testUtil/createTestEditor'; import overwriteModeExtension, { toggleOverwrite } from './overwriteModeExtension'; import typeText from '../testUtil/typeText'; import pressReleaseKey from '../testUtil/pressReleaseKey'; +import getLastAnnouncement from '../testUtil/getLastAnnouncement'; const createEditor = async (initialText: string, defaultEnabled = false) => { const editor = await createTestEditor(initialText, EditorSelection.cursor(0), [], [ @@ -54,4 +55,14 @@ describe('overwriteModeExtension', () => { expect(editor.state.doc.toString()).toBe('Test! This is a test! test\nTest'); }); + + test('should announce when toggling overwrite', async () => { + const editor = await createEditor('\nTest'); + + pressReleaseKey(editor, { key: 'Insert', code: 'Insert' }); + expect(getLastAnnouncement(editor)).toBe('Overwrite mode enabled'); + + pressReleaseKey(editor, { key: 'Insert', code: 'Insert' }); + expect(getLastAnnouncement(editor)).toBe('Overwrite mode disabled'); + }); }); diff --git a/packages/editor/CodeMirror/utils/overwriteModeExtension.ts b/packages/editor/CodeMirror/utils/overwriteModeExtension.ts index 762bd0e00ac..8e2a3fba791 100644 --- a/packages/editor/CodeMirror/utils/overwriteModeExtension.ts +++ b/packages/editor/CodeMirror/utils/overwriteModeExtension.ts @@ -1,5 +1,6 @@ import { keymap, EditorView } from '@codemirror/view'; import { StateField, Facet, StateEffect } from '@codemirror/state'; +import { _ } from '../../localization'; const overwriteModeFacet = Facet.define({ combine: values => values[0] ?? false, @@ -67,8 +68,14 @@ const overwriteModeExtension = [ keymap.of([{ key: 'Insert', run: (view) => { + const newEnabled = !view.state.field(overwriteModeState); view.dispatch({ - effects: toggleOverwrite.of(!view.state.field(overwriteModeState)), + effects: [ + toggleOverwrite.of(newEnabled), + EditorView.announce.of( + newEnabled ? _('Overwrite mode enabled') : _('Overwrite mode disabled'), + ), + ], }); return false; },