Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/handlers/editorFileTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ let dragSessionId = 0;

const MIN_SCROLL_SPEED = 2;
const MAX_SCROLL_SPEED = 14;
const REORDER_DURATION = 0.28;
const RELEASE_DURATION = 0.25;
const REORDER_DURATION_SECONDS = 0.28;
const RELEASE_DURATION_SECONDS = 0.25;
const SPRING_EASING = [0.2, 1, 0.4, 1];

/** @type {WeakMap<HTMLElement, {cancel?: function(): void}>} */
Expand Down Expand Up @@ -266,7 +266,7 @@ function finishDrag(shouldSettleClone) {
{
duration: document.body.classList.contains("no-animation")
? 0
: RELEASE_DURATION,
: RELEASE_DURATION_SECONDS,
ease: SPRING_EASING,
},
)
Expand Down Expand Up @@ -667,7 +667,7 @@ function animateTabReorder($parent, previousRects) {
{
duration: document.body.classList.contains("no-animation")
? 0
: REORDER_DURATION,
: REORDER_DURATION_SECONDS,
ease: SPRING_EASING,
},
);
Expand Down
19 changes: 14 additions & 5 deletions src/lib/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2679,17 +2679,26 @@ async function EditorManager($header, $body) {
const previousEditor = editor;
const previousContainer = $container;
const previousTouchSelectionController = touchSelectionController;
const restoreContext = () => {
editor = previousEditor;
$container = previousContainer;
touchSelectionController = previousTouchSelectionController;
};

editor = pane.editor;
$container = pane.editorContainer || $container;
touchSelectionController = pane.touchSelectionController || null;

try {
return callback();
} finally {
editor = previousEditor;
$container = previousContainer;
touchSelectionController = previousTouchSelectionController;
const result = callback();
if (result && typeof result.then === "function") {
return Promise.resolve(result).finally(restoreContext);
Comment on lines +2694 to +2695

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Module-level globals remain overridden during async window

When the callback returns a Promise the module-level editor, $container, and touchSelectionController stay pointing at the pane's values until the promise settles. If any synchronous code (event handlers, scheduled timers, etc.) runs in that window and reads those globals, it will see the pane's context rather than the active editor's. This is not a regression from the old try/finally (which restored too early), but it is a latent race that could surface if more async callers are added. A comment here noting the interleaving risk would help future readers.

All three current call sites pass synchronous lambdas, so there is no present breakage — just something worth documenting.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}
restoreContext();
return result;
} catch (error) {
restoreContext();
throw error;
}
}

Expand Down