diff options
author | bptato <nincsnevem662@gmail.com> | 2021-12-21 17:21:50 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-12-21 17:21:50 +0100 |
commit | 72979b36ddca08fd985ff7e263cb726f61adf498 (patch) | |
tree | e8460880801b14c8f5559c95f178c598a2414a7f /src | |
parent | 8a1611e1c6c81b4ee5b7f33f3f539ee1db53045e (diff) | |
download | chawan-72979b36ddca08fd985ff7e263cb726f61adf498.tar.gz |
No anchor error message
Diffstat (limited to 'src')
-rw-r--r-- | src/client.nim | 20 | ||||
-rw-r--r-- | src/io/buffer.nim | 3 |
2 files changed, 17 insertions, 6 deletions
diff --git a/src/client.nim b/src/client.nim index b644f5d9..ca2ad00c 100644 --- a/src/client.nim +++ b/src/client.nim @@ -29,13 +29,17 @@ proc newClient*(): Client = result.currentbuffer = -1 func pbuffer(client: Client): Buffer = - return client.buffers[client.currentbuffer - 1] + if client.currentbuffer > 0: + return client.buffers[client.currentbuffer - 1] + return nil func buffer(client: Client): Buffer = return client.buffers[client.currentbuffer] func nbuffer(client: Client): Buffer = - return client.buffers[client.currentbuffer + 1] + if client.currentbuffer < client.buffers.len - 1: + return client.buffers[client.currentbuffer + 1] + return nil func puri(client: Client): Uri = if client.currentbuffer > 0: @@ -125,7 +129,9 @@ proc gotoURL(client: Client, url: Uri) = var newuri = url client.addBuffer() newuri = client.mergeUrls(client.puri, newuri) - if client.puri != url or newuri.anchor == "": + let newanchor = newuri.anchor + newuri.anchor = "" + if client.puri != newuri or newanchor == "": let s = client.getPageUri(newuri) if s != nil: client.buffer.source = s.readAll() #TODO @@ -133,10 +139,12 @@ proc gotoURL(client: Client, url: Uri) = client.discardBuffer() client.buffer.setStatusMessage("Couldn't load " & $newuri) return - elif newuri.anchor != "": + elif newanchor != "": + if not client.pbuffer.hasAnchor(newanchor): + client.discardBuffer() + client.buffer.setStatusMessage("Couldn't find anchor " & newanchor) + return client.buffer.source = client.pbuffer.source - let newanchor = newuri.anchor - newuri = client.buffer.location newuri.anchor = newanchor client.buffer.setLocation(newuri) client.setupBuffer() diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 775e6557..0c600441 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -235,6 +235,9 @@ func atPercentOf(buffer: Buffer): int = if buffer.lines.len == 0: return 100 return (100 * (buffer.cursory + 1)) div buffer.numLines +func hasAnchor*(buffer: Buffer, anchor: string): bool = + return buffer.document.getElementById(anchor) != nil + proc addLine(buffer: Buffer) = buffer.lines.addLine() |