Make checking boxes not require full page reload
This commit is contained in:
parent
cb24ab18c5
commit
1772e57ee8
3 changed files with 46 additions and 13 deletions
|
|
@ -336,7 +336,11 @@ func DeleteNote(uid string) error {
|
|||
return os.Remove(filename)
|
||||
}
|
||||
|
||||
type toggleCheckboxTransformer struct{ nthBox int }
|
||||
type toggleCheckboxTransformer struct {
|
||||
nthBox int
|
||||
boxToggled bool
|
||||
boxChecked bool
|
||||
}
|
||||
|
||||
func (t *toggleCheckboxTransformer) Transform(node *ast.Document, reader text.Reader, pc parser.Context) {
|
||||
boxesFound := 0
|
||||
|
|
@ -358,6 +362,8 @@ func (t *toggleCheckboxTransformer) Transform(node *ast.Document, reader text.Re
|
|||
}
|
||||
|
||||
box.IsChecked = !box.IsChecked
|
||||
t.boxToggled = true
|
||||
t.boxChecked = box.IsChecked
|
||||
return ast.WalkStop, nil
|
||||
})
|
||||
}
|
||||
|
|
@ -380,8 +386,8 @@ func renderTaskCheckBox(writer util.BufWriter, source []byte, node ast.Node, ent
|
|||
return ast.WalkContinue, err
|
||||
}
|
||||
|
||||
func (n *Note) ToggleBox(nthBox int) {
|
||||
checkboxTransformer := toggleCheckboxTransformer{nthBox: nthBox}
|
||||
func (n *Note) ToggleBox(nthBox int) (bool, bool) {
|
||||
checkboxTransformer := toggleCheckboxTransformer{nthBox: nthBox, boxToggled: false}
|
||||
transformer := util.Prioritized(&checkboxTransformer, 0)
|
||||
|
||||
renderer := markdown.NewRenderer()
|
||||
|
|
@ -397,6 +403,8 @@ func (n *Note) ToggleBox(nthBox int) {
|
|||
md.Convert(n.Body, &buf)
|
||||
n.Body = buf.Bytes()
|
||||
n.Save()
|
||||
|
||||
return checkboxTransformer.boxToggled, checkboxTransformer.boxChecked
|
||||
}
|
||||
|
||||
func (n *Note) HasTag(tag string) bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue