mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Execute Ctrl+C/V/X/A through execCommand in editor (so we can customize it)
This commit is contained in:
parent
c01c4b642b
commit
7f7e5c2702
3 changed files with 11 additions and 3 deletions
|
@ -1052,7 +1052,7 @@ $editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
|
||||||
|
|
||||||
class EditorWebView(AnkiWebView):
|
class EditorWebView(AnkiWebView):
|
||||||
def __init__(self, parent: QWidget, editor: Editor) -> None:
|
def __init__(self, parent: QWidget, editor: Editor) -> None:
|
||||||
AnkiWebView.__init__(self, title="editor")
|
AnkiWebView.__init__(self, title="editor", mac_default_shortcuts=False)
|
||||||
self.editor = editor
|
self.editor = editor
|
||||||
self.setAcceptDrops(True)
|
self.setAcceptDrops(True)
|
||||||
self._markInternal = False
|
self._markInternal = False
|
||||||
|
|
|
@ -210,7 +210,7 @@ class WebContent:
|
||||||
|
|
||||||
class AnkiWebView(QWebEngineView):
|
class AnkiWebView(QWebEngineView):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, parent: Optional[QWidget] = None, title: str = "default"
|
self, parent: Optional[QWidget] = None, title: str = "default", *, mac_default_shortcuts: bool = True
|
||||||
) -> None:
|
) -> None:
|
||||||
QWebEngineView.__init__(self, parent=parent)
|
QWebEngineView.__init__(self, parent=parent)
|
||||||
self.set_title(title)
|
self.set_title(title)
|
||||||
|
@ -238,7 +238,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
context=Qt.WidgetWithChildrenShortcut,
|
context=Qt.WidgetWithChildrenShortcut,
|
||||||
activated=self.onEsc,
|
activated=self.onEsc,
|
||||||
)
|
)
|
||||||
if isMac:
|
if isMac and mac_default_shortcuts:
|
||||||
for key, fn in [
|
for key, fn in [
|
||||||
(QKeySequence.Copy, self.onCopy),
|
(QKeySequence.Copy, self.onCopy),
|
||||||
(QKeySequence.Paste, self.onPaste),
|
(QKeySequence.Paste, self.onPaste),
|
||||||
|
@ -248,6 +248,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
QShortcut( # type: ignore
|
QShortcut( # type: ignore
|
||||||
key, self, context=Qt.WidgetWithChildrenShortcut, activated=fn
|
key, self, context=Qt.WidgetWithChildrenShortcut, activated=fn
|
||||||
)
|
)
|
||||||
|
|
||||||
QShortcut( # type: ignore
|
QShortcut( # type: ignore
|
||||||
QKeySequence("ctrl+shift+v"),
|
QKeySequence("ctrl+shift+v"),
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
import { filterHTML } from "html-filter";
|
import { filterHTML } from "html-filter";
|
||||||
import { updateActiveButtons, disableButtons } from "./toolbar";
|
import { updateActiveButtons, disableButtons } from "./toolbar";
|
||||||
import { setupI18n, ModuleName } from "lib/i18n";
|
import { setupI18n, ModuleName } from "lib/i18n";
|
||||||
|
import { registerShortcut } from "lib/shortcuts";
|
||||||
|
import { bridgeCommand } from "./lib";
|
||||||
|
|
||||||
import "./fields.css";
|
import "./fields.css";
|
||||||
|
|
||||||
|
@ -40,6 +42,11 @@ customElements.define("anki-editing-area", EditingArea, { extends: "div" });
|
||||||
customElements.define("anki-label-container", LabelContainer, { extends: "div" });
|
customElements.define("anki-label-container", LabelContainer, { extends: "div" });
|
||||||
customElements.define("anki-editor-field", EditorField, { extends: "div" });
|
customElements.define("anki-editor-field", EditorField, { extends: "div" });
|
||||||
|
|
||||||
|
registerShortcut(() => document.execCommand("copy"), "Control+C");
|
||||||
|
registerShortcut(() => document.execCommand("cut"), "Control+X");
|
||||||
|
registerShortcut(() => document.execCommand("selectAll"), "Control+A");
|
||||||
|
registerShortcut(() => bridgeCommand("paste"), "Control+Shift+V");
|
||||||
|
|
||||||
export function getCurrentField(): EditingArea | null {
|
export function getCurrentField(): EditingArea | null {
|
||||||
return document.activeElement instanceof EditingArea
|
return document.activeElement instanceof EditingArea
|
||||||
? document.activeElement
|
? document.activeElement
|
||||||
|
|
Loading…
Reference in a new issue