Add toggle for mode indicator with set modeindicator true|false

This commit is contained in:
Oliver Blanthorn 2018-04-23 21:28:46 +01:00
parent 47409e4fd2
commit e9f6afeb9c
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 32 additions and 26 deletions

View file

@ -221,6 +221,7 @@ const DEFAULTS = o({
cursorpos: "end",
theme: "default", // currently available: "default", "dark"
modeindicator: "true",
// Default logging levels - 2 === WARNING
logging: o({

View file

@ -69,32 +69,37 @@ if (
}
// Really bad status indicator
let statusIndicator = document.createElement("span")
statusIndicator.className = "cleanslate TridactylStatusIndicator"
window.addEventListener("DOMContentLoaded", () => {
statusIndicator.textContent = state.mode || "normal"
document.body.appendChild(statusIndicator)
})
config.getAsync("modeindicator").then(mode => {
if (mode !== "true") return
browser.storage.onChanged.addListener((changes, areaname) => {
if (areaname === "local" && "state" in changes) {
let mode = changes.state.newValue.mode
if (
dom.isTextEditable(document.activeElement) &&
!["input", "ignore"].includes(mode)
) {
statusIndicator.textContent = "insert"
// this doesn't work; statusIndicator.style is full of empty string
// statusIndicator.style.borderColor = "green !important"
// need to fix loss of focus by click: doesn't do anything here.
} else if (
mode === "insert" &&
!dom.isTextEditable(document.activeElement)
) {
statusIndicator.textContent = "normal"
// statusIndicator.style.borderColor = "lightgray !important"
} else {
statusIndicator.textContent = mode
let statusIndicator = document.createElement("span")
statusIndicator.className = "cleanslate TridactylStatusIndicator"
window.addEventListener("DOMContentLoaded", () => {
statusIndicator.textContent = state.mode || "normal"
document.body.appendChild(statusIndicator)
})
browser.storage.onChanged.addListener((changes, areaname) => {
if (areaname === "local" && "state" in changes) {
let mode = changes.state.newValue.mode
if (
dom.isTextEditable(document.activeElement) &&
!["input", "ignore"].includes(mode)
) {
statusIndicator.textContent = "insert"
// this doesn't work; statusIndicator.style is full of empty string
// statusIndicator.style.borderColor = "green !important"
// need to fix loss of focus by click: doesn't do anything here.
} else if (
mode === "insert" &&
!dom.isTextEditable(document.activeElement)
) {
statusIndicator.textContent = "normal"
// statusIndicator.style.borderColor = "lightgray !important"
} else {
statusIndicator.textContent = mode
}
}
}
if (config.get("modeindicator") !== "true") statusIndicator.remove()
})
})