performance and delta fixes

pull/8/head
Stephen Searles 8 years ago
parent ffd14c5795
commit 9591120da9
  1. 11
      caddyhugo.go
  2. 10
      templates.go

@ -309,6 +309,13 @@ func (ch *CaddyHugo) doc(r *http.Request) (*docref, error) {
doc: acedoc.NewString(string(contents)),
tmpdir: tmpdir,
}
err = ref.doc.LogToFile(path.Join(ch.Site.Root, "logs", r.URL.Path[len("/hugo/edit/"):]))
if err != nil {
fmt.Println(err)
return nil, err
}
ch.docs[name] = ref
hugoCmd := exec.Command("hugo", "--watch", "-D", "-d", ref.tmpdir)
@ -347,11 +354,12 @@ func (ch *CaddyHugo) doc(r *http.Request) (*docref, error) {
idleTime := time.Duration(idleTicks) * WebsocketFileTicker
if idleTime >= IdleWebsocketTimeout {
err := ch.Publish()
fmt.Printf("idle for %v, quitting", idleTime)
fmt.Printf("idle for %v, quitting\n", idleTime)
if err != nil {
fmt.Printf(", error publishing: %v\n", err)
}
ref.doc.Close()
os.RemoveAll(tmpdir)
delete(ch.docs, name)
ch.mtx.Unlock()
@ -421,6 +429,7 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int
defer func() {
ch.mtx.Lock()
client.Close()
doc.clients--
ch.mtx.Unlock()
}()

@ -291,7 +291,7 @@ var EditPage = `<html>
console.log(cmDelta, "=>", aceDelta)
sawChanges = sawChangesBumpsTo;
uiBindings.sendQueue.push(aceDelta);
uiBindings.sendQueue.push.apply(uiBindings.sendQueue, aceDelta);
})
function cmDeltaToAce(cmDelta) {
@ -321,8 +321,14 @@ var EditPage = `<html>
aceDelta.start.column += cmDelta.from.ch;
}
if (isRemove && ((cmDelta.text.length > 0 && cmDelta.text[0].length > 0) || cmDelta.text.length > 1)) {
cmDelta.removed = [""];
var ret = [aceDelta];
ret.push.apply(ret, cmDeltaToAce(cmDelta));
return ret;
}
return aceDelta;
return [aceDelta];
}
function aceDeltaToCM(aceDelta) {

Loading…
Cancel
Save