As a user on Overleaf, I assume I do not have control over which patch is included for CodeMirror. Then, through a Userscript, I wonder if there is a way to let Ctrl+C yank (copy) to the system clipboard in visual mode?
Here is my current attempt that wasn’t doing anything. Actually, Ctrl+C wasn’t remapped at all. I wonder if there is a walk around for assigning shortcuts, for, say, the CodeMirror
object itself? The goal is just to yank the visual selection to the system clipboard. I don’t mind if the visual selection should remain there after the system clipboard is updated.
// ==UserScript==
// @name Overleaf Editor Custom VIM Keybindings (2023)
// @namespace http://tampermonkey.net/
// @version 0.0.1
// @match https://www.overleaf.com/project/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("UNSTABLE_editor:extensions", (event) => {
const { CodeMirror, CodeMirrorVim, extensions } = event.detail;
// Restore Ctrl+C to copy into system clipboard
CodeMirrorVim.Vim.defineAction('CopySelection', copy_in_visual_mode);
CodeMirrorVim.Vim.mapCommand("<c-c>", 'action', 'CopySelection');
});
})();
// Clipboard access on Windows machines
function copy_in_visual_mode(cm) {
document.execCommand('copy');
alert("Triggered the copy function");
}
According to this issue, the +
register is made available to Vim mode. Yet, on Overleaf, with :reg
, I don’t see it.
Alternatively, it would also be helpful to know if a keyboard shortcut can be assigned to quickly toggle the Vim mode.