Skip to content

Commit

Permalink
editor: don't paste on middle click to close tab
Browse files Browse the repository at this point in the history
To avoid the Linux feature of pasting on middle click, we need to
consume the mouse up event in the browser on middle click instead of
mouse down.

This also sets the `selectionClipboard` editor option to false which
should disable the feature altogether in the monaco editor but the
setting seems to be broken in the browser[1].

[1]: microsoft/vscode#181050

Fixes: pybricks/support#1046
  • Loading branch information
dlech committed Apr 27, 2023
1 parent 82df743 commit fa18060
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
### Added
- Added warning message when hub has newer Pybricks Profile version than supported version.

### Fixed
- Fix pasting selection when middle click to close file on Linux ([support#1046]).

[support#1046]: https://github.com/pybricks/support/issues/1046

## [2.2.0-beta.3] - 2023-04-24

### Added
Expand Down
8 changes: 5 additions & 3 deletions src/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2022 The Pybricks Authors
// Copyright (c) 2020-2023 The Pybricks Authors

import './editor.scss';
import {
Expand Down Expand Up @@ -263,7 +263,8 @@ const EditorTabs: React.VoidFunctionComponent<EditorTabsProps> = ({ onChange })
);

// close tab when middle-clicked
const handleMouseDown = useCallback(
// NB: this has to be on mouse up event to prevent middle-click paste on Linux
const handleMouseUp = useCallback(
(e: React.MouseEvent, uuid: UUID) => {
if (e.button === 1) {
dispatch(editorCloseFile(uuid));
Expand Down Expand Up @@ -310,7 +311,7 @@ const EditorTabs: React.VoidFunctionComponent<EditorTabsProps> = ({ onChange })
key={uuid}
id={uuid}
onKeyDown={(e) => handleKeyDown(e, uuid)}
onMouseDown={(e) => handleMouseDown(e, uuid)}
onMouseUp={(e) => handleMouseUp(e, uuid)}
>
<TabLabel
id={`${labelId}.${uuid}`}
Expand Down Expand Up @@ -472,6 +473,7 @@ const Editor: React.VFC = () => {
rulers: [80],
lineNumbersMinChars: 4,
wordBasedSuggestions: false,
selectionClipboard: false, // don't copy selection on Linux
});

monacoEditor.focus();
Expand Down

0 comments on commit fa18060

Please sign in to comment.