Anders Kaseorg
e257253e64
emoji_codes: Replace JS module with JSON module.
...
webpack optimizes JSON modules using JSON.parse("{…}"), which is
faster than the normal JavaScript parser.
Update the backend to use emoji_codes.json too instead of the three
separate JSON files.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 10:09:12 -08:00
Anders Kaseorg
02511bff1c
js: Automatically convert _.each to for…of.
...
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
shubhamgupta2956
aaa30df94c
Hotkeys: Change hotkeys behaviour on dropdown open.
...
Disables message_view_only hotkeys when dropdown menu is opened.
Fixes : #11990
2020-02-03 13:45:07 -08:00
Tim Abbott
6b79448e01
hotkey: Rename confusingly named is_editing_stream_name.
...
The feature is used for editing stream descriptions as well, and in
any case, what's important is that it's a content-editable widget (aka
a form of input box).
2020-01-29 11:24:58 -08:00
Anders Kaseorg
28f3dfa284
js: Automatically convert var to let and const in most files.
...
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`. It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00
Yashashvi Dave
251ed94bfc
static/js/common: Use `platform` navigator to detect MacOS.
...
Replace `userAgent` navigator with `platform` navigator
to detect user's OS.
2019-06-24 14:04:42 -07:00
Yashashvi Dave
371343709b
static/js/common: Extract function `has_mac_keyboard`.
2019-06-24 14:04:42 -07:00
Vaibhav
d3b201337e
copy_and_paste: Bind default copy handler to hotkeys.
...
This removes the 'copy' event listener and binds the copy handler
to `Ctrl+C` or `Cmd+C` (OSX) keys;
2019-05-13 17:58:12 -07:00
vinitS101
d6fb15616d
hotkeys: Add `e` for edit selected message.
...
Adds 'e' as a hotkey for editing the selected message.
Changes to the Keyboard Shortcuts menu to reflect this change.
Fixes #11866 .
2019-04-13 18:52:27 -07:00
Rohitt Vashishtha
ee3b4f3ee9
hotkeys: Map `CTRL + .` to narrow to compose box target.
...
Also adds relevant tests and documentation. We currently
do not narrow to a new topic, and instead just narrow to
the stream. Similarly, we do not narrow to a PM if any of
the recipients are invalid.
2018-12-04 13:58:00 -08:00
Steve Howell
43f25eb4a5
Clean up code to open "Create stream" panel.
...
This fixes a bug where hitting the "n" hotkey was
causing double work related to the hashchange system.
The code is now organized like this:
do_open_create_stream() does the GUI piece
We call the above directly for hash changes.
For in-app actions, whether clicks or hotkeys,
we call open_create_stream(), which delegates
most of the work to do_open_create_stream() but
also updates the hash.
2018-12-02 18:40:00 -08:00
Steve Howell
91e4784b92
subject -> topic: Rename narrow.by_subject.
2018-11-14 23:24:06 -08:00
Tim Abbott
62bee26ea7
Revert "hotkey: Add hotkey to narrow to starred messages."
...
This reverts commit 144d21494e
.
2018-08-13 15:05:36 -07:00
Joshua Pan
144d21494e
hotkey: Add hotkey to narrow to starred messages.
...
Fixes #9684 .
2018-08-13 11:39:32 -07:00
Marco Burstein
9643c8ed26
hotkeys: Deactivate `ctrl + shift` hotkeys.
...
This disables `ctrl + shift + [`, while `ctrl + [` will still trigger
an action.
Also, add a test for ensuring that the `ctrl + shift` combinations fall
through.
2018-06-22 09:10:23 -04:00
Marco Burstein
56f711d5ff
hotkeys: Deactivate `cmd-or-ctrl + shift` hotkeys.
...
This disables `cmd-or-ctrl + shift + k` and `cmd-or-ctrl + shift + s`,
while `cmd-or-ctrl + k` and `cmd-or-ctrl + s` will still trigger
actions.
Also, add tests for ensuring that the `cmd-or-ctrl + shift`
combinations fall through.
Fix #9779 .
2018-06-22 09:10:23 -04:00
Shubham Padia
5f9cdf9b08
popovers: Enable keyboard navigation on user profile menu.
...
Fixes #9318 .
Calls popovers.user_info_popover_handle_keyboard in process_hotkey.js.
Makes popovers.message_info_popped public.
2018-06-13 05:57:14 -04:00
Steve Howell
e7e38253ec
settings: Add better keyboard navigation for panel menus.
...
You can now use all four arrow keys intuitively in the
Settings/Organization panel menus.
2018-06-06 09:42:33 -07:00
Anupam Dagar
0e8081093b
hotkey: Add deprecation notice for '*' hotkey.
2018-06-02 08:59:42 -07:00
Anupam Dagar
9674a139bf
hotkeys: Change * to Ctr+s for starring a message.
...
Fixes : #9613 .
2018-06-01 09:53:15 -07:00
Tim Abbott
5a5ca12f6f
hotkey: Move ctrl+[ back from cmd+[.
...
This was incorrectly changed; the goal here is to match what vim does
for this keyboard shortcut.
Fixes #9525 .
2018-05-24 08:31:55 -07:00
Steve Howell
42435db492
Add run_test helper for individual tests.
...
This run_test helper sets up a convention that allows
us to give really short tracebacks for errors, and
eventually we can have more control over running
individual tests. (The latter goal has some
complications, since we often intentionally leak
setup in tests.)
2018-05-15 08:24:44 -07:00
Tim Abbott
df98fd5cd9
hotkey: Make it possible to use ctrl+K from inside compose.
...
This works for other text boxes as well, but compose is the main one
that one would want to do a search from.
It's possible we'll find after doing this that "getting back into
compose" becomes a problem, but I guess we can handle that when the
time comes.
2018-05-06 19:30:31 -07:00
Aastha Gupta
66edc003ca
hotkey: Make 'Ctrl' hotkeys work with 'CMD' on MacOS.
...
We only have a couple hotkeys with this model, but they should both
do the correct corresponding thing on MacOS.
2018-05-06 19:21:36 -07:00
Aastha Gupta
19806a0283
keyboard UI: Add Ctrl + k hotkey.
...
Fixes #8216
This commit binds the Ctrl + k to go to the search bar.
2018-05-06 19:19:00 -07:00
Steve Howell
e70203ad55
node tests: Use zjquery in hotkey.js.
2018-04-17 17:52:19 -07:00
Anurag Sharma
1227857de6
hotkeys: Replace C with x for composing PM.
...
Pressing the 'x' key can now be used to compose a PM.
Pressing the 'C' key displays a modal that shows a deprecation notice.
Fixes #6548 .
2018-04-01 16:13:05 -07:00
Steve Howell
9ce9c2f9db
Extract info_overlay.js.
...
There are several ways we open help for keyboard shortcuts,
markdown help, and search operators.
- from the gear menu
- from the compose box
- from the search box
- hitting ? for keyboard help
- arrowing/clicking through the tabs
This just moves the relevant code into a module and changes a
bunch of one-line calls in various places.
2018-03-30 09:07:23 -07:00
Shubham Dhama
3b92f6115a
hotkey: Add 'delete' to delete focused draft.
2018-03-09 13:30:09 -08:00
Abhigyan Khaund
a75f0aa594
hotkeys: Add "p" to narrow to next unread PM thread.
...
This works simimlar to the "n" key for next topics.
This commit does a few things:
* It wires up the hotkey to an existing function
that could change narrows.
* It adds documentation.
* It adds logic to make sure the compose box does
not open.
@showell helped a bit with the wording of comments here.
Fixes #4874
2018-02-27 07:20:31 -05:00
Balaji2198
f49d9d016f
hotkeys: Add '>' as a hotkey for quote and reply to message.
...
Tweaked by tabbott to fix a few minor issues.
Fixes #8146 .
2018-02-02 17:37:53 -08:00
Brock Whittaker
2252d7e5f6
Revert "dark-mode: Add "T" hotkey for dark mode theme."
...
This reverts commit ce62abce73
.
Fixes #7678 .
2017-12-11 15:59:02 -06:00
Brock Whittaker
ce62abce73
dark-mode: Add "T" hotkey for dark mode theme.
2017-11-15 16:45:34 -08:00
derAnfaenger
19bc55aa45
Fix various typos.
...
The typos and their corrections were found with the
aid of https://github.com/lucasdemarchi/codespell .
2017-11-09 16:26:38 +01:00
Steve Howell
6304aea4bc
node tests: Use zrequire in hotkey.js.
2017-11-08 12:24:17 -08:00
Cynthia Lin
f63585bd6d
hotkeys: Ensure navigation hotkeys do not work while overlay is open.
...
Fixes #7123 .
2017-11-03 15:38:10 -07:00
Harshit Bansal
48ac282667
hotkeys: Remap ':' to close the reactions popover in case of empty search.
...
Fixes : #6806 .
2017-10-05 19:05:27 +05:30
Cynthia Lin
c87ecf0f63
hotkeys: Prevent drafts overlay from showing while lightbox is open.
...
Fixes #6757 .
2017-10-03 08:36:54 -07:00
Harshit Bansal
ef4337edcb
hotkey: Remap `+` key to use canonical name for thumbs up emoji.
2017-09-26 16:50:00 -07:00
Joshua Pan
178f5080cf
hotkey.js: Switch 'q' and 'w' hotkeys.
...
On a standard keyboard, 'q' is to the left of 'w', so it makes sense
for the hotkeys for the left and right sidebars to be `q` and `w`,
respectively, not the other way around.
2017-09-25 12:14:07 -07:00
Joshua Pan
b201e2c311
hotkey.js: Simplify ctrl+[ hotkey logic.
2017-09-19 19:07:30 -07:00
Joshua Pan
d387291b6c
reactions.js: Extract open_reactions_popover().
...
Added tests for open_reactions_popover() also.
2017-09-19 19:07:30 -07:00
Cynthia Lin
bd7d9da668
hotkeys: Disable 'n' stream creation if user cannot create streams.
...
Tweaked by tabbott to handle a corner case and add test coverage.
2017-09-16 09:12:38 -07:00
Joshua Pan
42b05912f8
hotkeys: Make '?' hotkey toggle.
2017-09-14 05:56:55 -07:00
Steve Howell
29c05c82f0
Fix A/D hotkeys for cycling through stream narrows.
...
We now use similar code for A/D hotkeys as we do for the "n"
key.
The old code was using jQuery operations that got tripped up
by our splitters between active and inactive streams.
Fixes #4569
2017-08-16 15:45:47 -07:00
Jack Zhang
c69b5d7d65
hotkey: Add support for hotspots on enter.
2017-08-05 18:32:37 -07:00
Joshua Pan
ac64ee355d
compose_actions.js: Allow compose to empty narrow.
...
This allows r/enter hotkeys to compose to
an empty narrow (no messages).
Fixes #4500 .
2017-06-27 14:06:59 -04:00
Cynthia Lin
e832ebdc98
hotkeys: Add collapse/show message hotkey.
...
Fixes #4540
2017-06-21 15:54:09 -04:00
Cynthia Lin
a9afe43735
hotkeys: Add `u` hotkey for opening message sender profile.
...
Fixes #4873
2017-06-21 10:38:05 -04:00
Steve Howell
d2b710b307
Add maybe_show_keyboard_shortcuts().
...
This prevents some strange UI experiences and some blueslip
errors by not opening keyboard help when other overlays or
popovers are open.
2017-06-15 10:15:29 -04:00