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)), doc: acedoc.NewString(string(contents)),
tmpdir: tmpdir, 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 ch.docs[name] = ref
hugoCmd := exec.Command("hugo", "--watch", "-D", "-d", ref.tmpdir) 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 idleTime := time.Duration(idleTicks) * WebsocketFileTicker
if idleTime >= IdleWebsocketTimeout { if idleTime >= IdleWebsocketTimeout {
err := ch.Publish() err := ch.Publish()
fmt.Printf("idle for %v, quitting", idleTime) fmt.Printf("idle for %v, quitting\n", idleTime)
if err != nil { if err != nil {
fmt.Printf(", error publishing: %v\n", err) fmt.Printf(", error publishing: %v\n", err)
} }
ref.doc.Close()
os.RemoveAll(tmpdir) os.RemoveAll(tmpdir)
delete(ch.docs, name) delete(ch.docs, name)
ch.mtx.Unlock() ch.mtx.Unlock()
@ -421,6 +429,7 @@ func (ch *CaddyHugo) DeltaWebsocket(w http.ResponseWriter, r *http.Request) (int
defer func() { defer func() {
ch.mtx.Lock() ch.mtx.Lock()
client.Close()
doc.clients-- doc.clients--
ch.mtx.Unlock() ch.mtx.Unlock()
}() }()

@ -291,7 +291,7 @@ var EditPage = `<html>
console.log(cmDelta, "=>", aceDelta) console.log(cmDelta, "=>", aceDelta)
sawChanges = sawChangesBumpsTo; sawChanges = sawChangesBumpsTo;
uiBindings.sendQueue.push(aceDelta); uiBindings.sendQueue.push.apply(uiBindings.sendQueue, aceDelta);
}) })
function cmDeltaToAce(cmDelta) { function cmDeltaToAce(cmDelta) {
@ -321,8 +321,14 @@ var EditPage = `<html>
aceDelta.start.column += cmDelta.from.ch; 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) { function aceDeltaToCM(aceDelta) {

Loading…
Cancel
Save