Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for accesskey shortcuts #684

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions data/Help.page
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,27 @@ picture into a (markdown-formatted) page as follows: `![fido](fido.jpg)`.
If you uploaded a PDF `projection.pdf`, you can insert a link to it
using: `[projection](projection.pdf)`.

# Keyboard shortcuts

Gitit supports keyboard shortcuts similar to
[MediaWiki's](https://www.mediawiki.org/wiki/Manual:Access_keys).

Key Action
---- -------
f Move cursor to search box
r Recent activity
x Random page
z Front page
o Log in
e Edit current page
h View history
p Printable version
t Switch to discussion page
c Switch to content page
, Move cursor to edit box
b Move cursor to description of changes
p Preview
s Save
d Delete current page

Table: Access keys
4 changes: 2 additions & 2 deletions data/templates/pagetools.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<legend>This page</legend>
<ul>
<li><a href="$base$/_showraw$pageUrl$$if(revision)$?revision=$revision$$endif$">Raw page source</a></li>
<li><a href="$base$$pageUrl$?printable$if(revision)$&amp;revision=$revision$$endif$">Printable version</a></li>
<li><a href="$base$/_delete$pageUrl$">Delete this page</a></li>
<li><a href="$base$$pageUrl$?printable$if(revision)$&amp;revision=$revision$$endif$" accesskey="p">Printable version</a></li>
<li><a href="$base$/_delete$pageUrl$" accesskey="d">Delete this page</a></li>
$if(feed)$
<li><a href="$base$/_feed$pageUrl$" type="application/atom+xml" rel="alternate" title="This page's ATOM Feed">Atom feed</a> <img alt="feed icon" src="$base$/img/icons/feed.png"/></li>
$endif$
Expand Down
8 changes: 4 additions & 4 deletions data/templates/sitenav.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<fieldset>
<legend>Site</legend>
<ul>
<li><a href="$base$/">Front page</a></li>
<li><a href="$base$/" accesskey="z">Front page</a></li>
<li><a href="$base$/_index">All pages</a></li>
<li><a href="$base$/_categories">Categories</a></li>
<li><a href="$base$/_random">Random page</a></li>
<li><a href="$base$/_activity">Recent activity</a></li>
<li><a href="$base$/_random" accesskey="x">Random page</a></li>
<li><a href="$base$/_activity" accesskey="r">Recent activity</a></li>
$if(wikiupload)$
<li><a href="$base$/_upload">Upload a file</a></li>
$endif$
Expand All @@ -16,7 +16,7 @@
<li><a href="$base$/Help">Help</a></li>
</ul>
<form action="$base$/_search" method="get" id="searchform">
<input type="text" name="patterns" id="patterns"/>
<input type="text" name="patterns" id="patterns" accesskey="f"/>
<input type="submit" name="search" id="search" value="Search"/>
</form>
<form action="$base$/_go" method="post" id="goform">
Expand Down
2 changes: 1 addition & 1 deletion data/templates/userbox.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<a href="$base$/_logout">Logout</a>
</noscript>
&nbsp;
<a id="loginlink" class="login" href="$base$/_login">Login / Get an account</a>
<a id="loginlink" class="login" href="$base$/_login" accesskey="o">Login / Get an account</a>
<a id="logoutlink" class="login" href="$base$/_logout">Logout <span id="logged_in_user"></span></a>
</div>
10 changes: 7 additions & 3 deletions src/Network/Gitit/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ getDiff fs file from to = do
" to " ++ fromMaybe "current" to) +++
pre ! [theclass "diff"] << map diffLineToHtml rawDiff

accesskey :: Char -> HtmlAttr
accesskey c = strAttr "accesskey" [c]

editPage :: Handler
editPage = withData editPage'

Expand Down Expand Up @@ -532,19 +535,20 @@ editPage' params = do
let editForm = gui (base' ++ urlForPage page) ! [identifier "editform"] <<
[ sha1Box
, textarea ! (readonly ++ [cols "80", name "editedText",
identifier "editedText"]) << raw
identifier "editedText", accesskey ',']) << raw
, br
, label ! [thefor "logMsg"] << "Description of changes:"
, br
, textfield "logMsg" ! (readonly ++ [value (logMsg `orIfNull` defaultSummary cfg) ])
, submit "update" "Save"
, textfield "logMsg" ! (readonly ++ [value (logMsg `orIfNull` defaultSummary cfg), accesskey 'b' ])
, submit "update" "Save" ! [ accesskey 's' ]
, primHtmlChar "nbsp"
, submit "cancel" "Discard"
, primHtmlChar "nbsp"
, input ! [thetype "button", theclass "editButton",
identifier "previewButton",
strAttr "onClick" "updatePreviewPane();",
strAttr "style" "display: none;",
accesskey 'p',
value "Preview" ]
, thediv ! [ identifier "previewpane" ] << noHtml
]
Expand Down
14 changes: 9 additions & 5 deletions src/Network/Gitit/Layout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ filledPageTemplate base' cfg layout htmlContents templ =

-- auxiliary functions:

accesskey :: Char -> HtmlAttr
accesskey c = strAttr "accesskey" [c]

linkForTab :: (Tab -> Html -> Html) -> String -> String -> Maybe String -> Tab -> Html
linkForTab tabli base' page _ HistoryTab =
tabli HistoryTab << anchor ! [href $ base' ++ "/_history" ++ urlForPage page] << "history"
tabli HistoryTab << anchor ! [href $ base' ++ "/_history" ++ urlForPage page, accesskey 'h'] << "history"
linkForTab tabli _ _ _ DiffTab =
tabli DiffTab << anchor ! [href ""] << "diff"
linkForTab tabli base' page rev ViewTab =
Expand All @@ -132,23 +135,24 @@ linkForTab tabli base' page rev ViewTab =
else s
in if isDiscussPage page
then tabli DiscussTab << anchor !
[href $ base' ++ urlForPage (origPage page)] << "page"
[href $ base' ++ urlForPage (origPage page), accesskey 'c'] << "page"
else tabli ViewTab << anchor !
[href $ base' ++ urlForPage page ++
case rev of
Just r -> "?revision=" ++ r
Nothing -> ""] << "view"
Nothing -> "", accesskey 'c'] << "view"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation (as of commit 94cb5a4) when looking at a revision of a page, the c accesskey is useless. There is no way to go from a revision to the current/latest version of the page, which MediaWiki supports. For example, on https://en.wikipedia.org/w/index.php?title=Human&oldid=1128628188 pressing the accesskey combination with c navigates to https://en.wikipedia.org/wiki/Human

After using this for a bit, I think it would be better to mimic MediaWiki and move accesskey="c" to a link, which would always go to the current version of the page, i.e. something along these lines:

diff --git a/data/templates/content.st b/data/templates/content.st
index 0d1229d..9c39d64 100644
--- a/data/templates/content.st
+++ b/data/templates/content.st
@@ -2,7 +2,7 @@
   $if(revision)$
     <h2 class="revision">Revision $revision$ (click the page title to view the current version)</h2>
   $endif$
-  <h1 class="pageTitle"><a href="$base$$pageUrl$">$pagetitle$</a></h1>
+  <h1 class="pageTitle"><a href="$base$$pageUrl$" accesskey="c">$pagetitle$</a></h1>
   <div class="subpages"><a href="../">&lt; parent directory</a>
     <a href="$base$$pageUrl$/">&gt; this directory</a>
   </div>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, however, would not work for switching from discussion pages (e.g. @Sandbox) to content pages. 🙁

linkForTab tabli base' page _ DiscussTab =
tabli (if isDiscussPage page then ViewTab else DiscussTab) <<
anchor ! [href $ base' ++ if isDiscussPage page then "" else "/_discuss" ++
urlForPage page] << "discuss"
urlForPage page, accesskey 't'] << "discuss"
linkForTab tabli base' page rev EditTab =
tabli EditTab << anchor !
[href $ base' ++ "/_edit" ++ urlForPage page ++
case rev of
Just r -> "?revision=" ++ r ++ "&" ++
urlEncodeVars [("logMsg", "Revert to " ++ r)]
Nothing -> ""] << if isNothing rev
Nothing -> "",
accesskey 'e'] << if isNothing rev
then "edit"
else "revert"

Expand Down