Merge pull request #3888 from tridactyl/editoreditor

Editoreditor
This commit is contained in:
Oliver Blanthorn 2021-08-13 14:05:32 +01:00 committed by GitHub
commit 1aec9931b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 17 deletions

View file

@ -15,6 +15,7 @@
"cleanslate": "^0.10.1",
"csp-serdes": "github:cmcaine/csp-serdes",
"css": "^3.0.0",
"editor-adapter": "^0.0.1",
"esbuild": "^0.12.8",
"fuse.js": "^6.4.6",
"nearley": "^2.20.1",

View file

@ -133,7 +133,7 @@ import * as DOM from "@src/lib/dom"
import * as CommandLineContent from "@src/content/commandline_content"
import * as scrolling from "@src/content/scrolling"
import { ownTab } from "@src/lib/webext"
import { wrap_input, getLineAndColNumber, rot13_helper, jumble_helper } from "@src/lib/editor_utils"
import { rot13_helper, jumble_helper } from "@src/lib/editor_utils"
import * as finding from "@src/content/finding"
import * as toys from "./content/toys"
import * as hinting from "@src/content/hinting"
@ -253,7 +253,7 @@ export async function rssexec(url: string, type?: string, ...title: string[]) {
}
/**
* Fills the element matched by `selector` with content and falls back to the last used input if the element can't be found. You probably don't want this; it's used internally for [[editor]].
* Fills the element matched by `selector` with content and falls back to the last used input if the element can't be found. You probably don't want this; it used to be used internally for [[editor]].
*
* That said, `bind gs fillinput null [Tridactyl](https://addons.mozilla.org/en-US/firefox/addon/tridactyl-vim/) is my favourite add-on` could probably come in handy.
*/
@ -313,6 +313,9 @@ export function removeTridactylEditorClass(selector: string) {
elem.className = elem.className.replace(" TridactylEditing ", "")
}
//#content_helper
import { getEditor } from "editor-adapter"
/**
* Opens your favourite editor (which is currently gVim) and fills the last used input with whatever you write into that file.
* **Requires that the native messenger is installed, see [[native]] and [[nativeinstall]]**.
@ -346,24 +349,18 @@ export async function editor() {
let ans
try {
let text = ""
let line = 0
let col = 0
wrap_input((t, start) => {
;[text, line, col] = getLineAndColNumber(t, start)
return [null, null, null]
})(elem)
// CodeMirror support
if (elem.parentNode?.parentElement?.className?.match(/CodeMirror/gi)) {
text = (elem.parentNode.parentElement as any).wrappedJSObject.CodeMirror.getValue()
}
const editor = getEditor(elem, { preferHTML: true })
const text = await editor.getContent()
const pos = await editor.getCursor()
const file = (await Native.temp(text, document.location.hostname)).content
const exec = await Native.editor(file, line, col)
console.log(exec)
const exec = await Native.editor(file, ...pos)
if (exec.code == 0) {
fillinput(selector, exec.content)
await editor.setContent(exec.content)
// TODO: ask the editor nicely where its cursor was left and use that
// for now just try to put it where it started at
await editor.setCursor(...pos)
// TODO: add annoying "This message was written with [Tridactyl](https://addons.mozilla.org/en-US/firefox/addon/tridactyl-vim/)" to everything written using editor
ans = [file, exec.content]

View file

@ -2218,6 +2218,13 @@ ecdsa-sig-formatter@1.0.11:
dependencies:
safe-buffer "^5.0.1"
editor-adapter@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/editor-adapter/-/editor-adapter-0.0.1.tgz#97b26c11543cc323cd6d908f1cb65b122689be5e"
integrity sha512-8ROHaAtYdhM4vQJaz2+p3KcjkWF3HKhNaVm/SKJjiYYDhvYpCvIbrRAzTSGv8mBEypAfQZ3uV+J5fXS1H3So4w==
dependencies:
typescript "^4.3.5"
emoji-regex@^7.0.1:
version "7.0.3"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
@ -6742,6 +6749,11 @@ typescript@^3.9.10:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8"
integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==
typescript@^4.3.5:
version "4.3.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4"
integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==
typical@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4"