mirror of
https://github.com/heyman/heynote.git
synced 2025-01-24 14:58:44 +01:00
Use fixed notation for math result values when they are copied to clipboard
This commit is contained in:
parent
51b2be3740
commit
4c44f32542
@ -7,20 +7,21 @@ import { getNoteBlockFromPos } from "./block"
|
|||||||
|
|
||||||
|
|
||||||
class MathResult extends WidgetType {
|
class MathResult extends WidgetType {
|
||||||
constructor(result) {
|
constructor(displayResult, copyResult) {
|
||||||
super()
|
super()
|
||||||
this.result = result
|
this.displayResult = displayResult
|
||||||
|
this.copyResult = copyResult
|
||||||
}
|
}
|
||||||
|
|
||||||
eq(other) { return other.result == this.result }
|
eq(other) { return other.displayResult == this.displayResult }
|
||||||
|
|
||||||
toDOM() {
|
toDOM() {
|
||||||
let wrap = document.createElement("span")
|
let wrap = document.createElement("span")
|
||||||
wrap.className = "heynote-math-result"
|
wrap.className = "heynote-math-result"
|
||||||
wrap.innerHTML = this.result
|
wrap.innerHTML = this.displayResult
|
||||||
wrap.addEventListener("click", (e) => {
|
wrap.addEventListener("click", (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
navigator.clipboard.writeText(this.result)
|
navigator.clipboard.writeText(this.copyResult)
|
||||||
const copyElement = document.createElement("i")
|
const copyElement = document.createElement("i")
|
||||||
copyElement.className = "heynote-math-result-copied"
|
copyElement.className = "heynote-math-result-copied"
|
||||||
copyElement.innerHTML = "Copied!"
|
copyElement.innerHTML = "Copied!"
|
||||||
@ -62,11 +63,18 @@ function mathDeco(view) {
|
|||||||
|
|
||||||
// if we got a result from math.js, add the result decoration
|
// if we got a result from math.js, add the result decoration
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
builder.add(line.to, line.to, Decoration.widget({widget: new MathResult(math.format(result, {
|
builder.add(line.to, line.to, Decoration.widget({
|
||||||
|
widget: new MathResult(
|
||||||
|
math.format(result, {
|
||||||
precision: 8,
|
precision: 8,
|
||||||
upperExp: 8,
|
upperExp: 8,
|
||||||
lowerExp: -6,
|
lowerExp: -6,
|
||||||
})), side: 1}))
|
}),
|
||||||
|
math.format(result, {
|
||||||
|
notation: "fixed",
|
||||||
|
}),
|
||||||
|
), side: 1},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos = line.to + 1
|
pos = line.to + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user