Skip to content
Open
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
34 changes: 23 additions & 11 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
// before sending to layout engine and interpret them into respective vim motion/command.
// Then implement those motions by sending relevant keystrokes. Essentially doing a keystroke to keystroke remapping.

const iframe = document.getElementsByTagName('iframe')[0] // https://stackoverflow.com/a/4388829
iframe.contentDocument.addEventListener('keydown', eventHandler, true)

const cursorTop = document.getElementsByClassName("kix-cursor-top")[0] // element to edit to show normal vs insert mode
let cursorTop = null
let mode = 'normal'
let tempnormal = false // State variable for indicating temperory normal mode
let multipleMotion = {
Expand Down Expand Up @@ -124,16 +121,19 @@ function switchModeToNormal() {
mode = 'normal'
updateModeIndicator(mode)

//caret indicating visual mode
cursorTop.style.opacity = 1
cursorTop.style.display = "block"
cursorTop.style.backgroundColor = "black"
cursorTop = cursorTop || document.getElementsByClassName("kix-cursor-top")[0]
if (cursorTop) {
cursorTop.style.opacity = 1
cursorTop.style.display = "block"
cursorTop.style.backgroundColor = "black"
}
}

function switchModeToInsert() {
mode = 'insert'
updateModeIndicator(mode)
cursorTop.style.opacity = 0
cursorTop = cursorTop || document.getElementsByClassName("kix-cursor-top")[0]
if (cursorTop) cursorTop.style.opacity = 0
}

function switchModeToWait() {
Expand Down Expand Up @@ -685,5 +685,17 @@ function activateTopLevelMenu(menuCaption) {
simulateClick(button);
}

// Initiate to Normal Mode
switchModeToNormal()
function initialize() {
const iframe = document.querySelector('.docs-texteventtarget-iframe')
if (!iframe || !iframe.contentDocument) return false
iframe.contentDocument.addEventListener('keydown', eventHandler, true)
switchModeToNormal()
return true
}

if (!initialize()) {
const observer = new MutationObserver(() => {
if (initialize()) observer.disconnect()
})
observer.observe(document.documentElement, { childList: true, subtree: true })
}