From b4b6201ae30b9ee3050f4af0625e605d33a66b4a Mon Sep 17 00:00:00 2001 From: Frederic COLLONVAL Date: Sat, 14 Oct 2023 19:32:31 +0200 Subject: [PATCH] Fix undo --- src/view.tsx | 11 ++++++++++- ui-tests/tests/replacePerItem.spec.ts | 6 ++---- ui-tests/tests/search.spec.ts | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/view.tsx b/src/view.tsx index 5ce2a17..e47c0a7 100644 --- a/src/view.tsx +++ b/src/view.tsx @@ -32,6 +32,7 @@ import { regexIcon } from '@jupyterlab/ui-components'; import type { CommandRegistry } from '@lumino/commands'; +import { PromiseDelegate } from '@lumino/coreutils'; import { Message } from '@lumino/messaging'; import React, { useEffect, useState } from 'react'; import { AskBoolean } from './askBoolean'; @@ -491,9 +492,17 @@ export class SearchReplaceView extends VDomRenderer { matches: SearchReplace.IReplacement[] ): Promise> { const widget = await this.openFile(path); - await widget.context.ready; + await Promise.all([widget.context.ready, widget.content.ready]); + const editor = widget.content.editor as CodeMirrorEditor; + // Add arbitrary delay for the shared model to set up properly its undo manager + const waitForTimeout = new PromiseDelegate(); + window.setTimeout(() => { + waitForTimeout.resolve(); + }, 300); + await waitForTimeout.promise; + // Sort from end to start to preserve match positions matches .sort((a, b) => { diff --git a/ui-tests/tests/replacePerItem.spec.ts b/ui-tests/tests/replacePerItem.spec.ts index 5bfa3ba..ccf0bf1 100644 --- a/ui-tests/tests/replacePerItem.spec.ts +++ b/ui-tests/tests/replacePerItem.spec.ts @@ -92,8 +92,7 @@ test('should replace results for a particular file only', async ({ page }) => { ); }); -// FIXME -test.skip('should undo replace results for a particular file only', async ({ +test('should undo replace results for a particular file only', async ({ page }) => { await page.getByRole('tab', { name: 'Search and Replace' }).click(); @@ -229,8 +228,7 @@ test('should replace results for a particular match only', async ({ page }) => { ); }); -// FIXME -test.skip('should undo replace results for a particular match only', async ({ +test('should undo replace results for a particular match only', async ({ page }) => { await page.getByRole('tab', { name: 'Search and Replace' }).click(); diff --git a/ui-tests/tests/search.spec.ts b/ui-tests/tests/search.spec.ts index 812f3e1..aa68716 100644 --- a/ui-tests/tests/search.spec.ts +++ b/ui-tests/tests/search.spec.ts @@ -271,7 +271,7 @@ test('should replace results on replace-all button', async ({ page }) => { await page .getByRole('textbox', { name: 'Search Files for Text' }) - .fill('hello'); + .fill('hola'); await Promise.all([ page.waitForResponse( response =>