Skip to content

Commit

Permalink
Refactoring for 1.0 #1542
Browse files Browse the repository at this point in the history
* integrate with neovim with native messaging.
* settle down the public APIs for setting snippets and document them.
* improve the build process with webpack.
* add unit tests.
* remove the Mermaid diagram generator, which is unnecessary for the extension.
  • Loading branch information
brookhong committed Nov 28, 2021
1 parent db96cd5 commit 4619ee2
Show file tree
Hide file tree
Showing 391 changed files with 10,168 additions and 112,181 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
dist/
coverage/
.DS_Store
.vscode/
package-lock.json
Expand Down
149 changes: 1 addition & 148 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Surfingkeys is doing its best to make full use of keyboard for web browsing, but
* [Dot to repeat previous action](#dot-to-repeat-previous-action)
* [Markdown preview](#markdown-preview)
* [Capture page](#capture-page)
* [Mermaid diagram generator](#mermaid-diagram-generator)
* [PDF viewer](#pdf-viewer)
* [Edit your own settings](#edit-your-own-settings)
* [License](#license)
Expand Down Expand Up @@ -488,13 +487,6 @@ There are some circumstances that you want to take a screenshot on a page, below

After one of above shortcuts pressed, you could see a popup of captured image, on which you could then right click with a MOUSE( 😢 ) to save as or copy into system clipboard.

## Mermaid diagram generator

[Mermaid](https://github.com/knsv/mermaid) is a great tool to generate diagrams and flowcharts from text in a similar manner as markdown.
Surfingkeys provides a simple frontend to generate diagrams from text in clipboard, and a vim editor to edit it.

`Ctrl-Alt-d` to open it.

## PDF viewer
To make Surfingkeys work for PDF files, Surfingkeys integrates PDF viewer from the notable [pdf.js](https://github.com/mozilla/pdf.js). When a pdf file is opened in Chrome, the PDF viewer will be launched, and you could use everything from Surfingkeys then.

Expand All @@ -504,146 +496,6 @@ Some functionalities are also available when you're using original pdf viewer, b

## Edit your own settings

### Map a keystroke to some action

mapkey(keystroke, help_string, action_code, [options])

| parameter | explanation |
|:---------------| :-----|
|**keystroke** | string, any keystroke to trigger the action|
|**help_string** | string, a help message to describe the action, which will displayed in help opened by `u`.|
|**action_code** | function, a Javascript function to be bound. If the function needs an argument, next pressed key will be fed to the function.|
|**options** | object, properties listed below|
|**domain** | regex[optional], a Javascript regex pattern to identify the domains that this mapping works, for example, `/github\.com/i` says that this mapping works only for github.com.|
|**repeatIgnore** | boolean[optional], whether this keystroke will be repeat by dot command.|

Just an example to map one keystroke to different functions on different sites,

mapkey('zz', 'Choose a tab', function() {
Front.chooseTab();
}, {domain: /github\.com/i});
mapkey('zz', 'Show usage', function() {
Front.showUsage();
}, {domain: /google\.com/i});

mapkey in visual mode and omnibar bar.

vmapkey(keystroke, help_string, action_code, [options])

### map a keystroke to another

map(new_keystroke, old_keystroke, [domain_pattern], [new_annotation])

imap(new_keystroke, old_keystroke, [domain_pattern], [new_annotation])

vmap(new_keystroke, old_keystroke, [domain_pattern], [new_annotation])

cmap(new_keystroke, old_keystroke, [domain_pattern], [new_annotation])

| parameter | explanation |
|:---------------| :-----|
|**new_keystroke** | string, the new keystroke that will be used.|
|**old_keystroke** | string, the existing keystroke that will be replaced, which means pressing it will not trigger any action.|
|**domain_pattern** | regex[optional], a Javascript regex pattern to identify the domains that this mapping works.|
|**new_annotation** | string[optional], use it instead of the annotation from old_keystroke if provided.|

### remove a keystroke mapping

Normal mode,

unmap(keystroke, [domain_pattern])

Insert mode,

iunmap(keystroke, [domain_pattern])

Visual mode,

vunmap(keystroke, [domain_pattern])

| parameter | explanation |
|:---------------| :-----|
|**keystroke** | string, the existing keystroke that will be removed.|
|**domain_pattern** | regex[optional], a Javascript regex pattern to identify the domains that this settings works.|

### remove all keystroke mappings

unmapAllExcept(keystrokes, [domain_pattern])

| parameter | explanation |
|:---------------| :-----|
|**keystrokes** | array of string, the existing keystrokes that will be removed.|
|**domain_pattern** | regex[optional], a Javascript regex pattern to identify the domains that this settings works.|

Example,

unmapAllExcept(['f', '/', '?']);

### Add search alias to omnibar

addSearchAlias(alias, prompt, search_url, suggestion_url, callback_to_parse_suggestion);

| parameter | explanation |
|:---------------| :-----|
|**alias** | one or several chars, used as search alias. When you input the string and press `space` in omnibar, it will switch to the related search engine.|
|**prompt** | a string to tell you which search engine will be used for following search|
|**search_url** | the URL for the search engine|
|**suggestion_url[optional]** | omnibar will list out search suggestions from the engine, if you provide suggestion_url and callback_to_parse_suggestion|
|**callback_to_parse_suggestion[optional]** | works with suggestion_url to provide search suggestion|

addSearchAliasX(alias, prompt, search_url, search_leader_key, suggestion_url, callback_to_parse_suggestion, only_this_site_key);

| parameter | explanation |
|:---------------| :-----|
|**search_leader_key** | one or several chars, used as search leader key, in case of that you would not like to use the default key `s`.|
|**only_this_site_key** | one or several chars, used as only-this-site-key, in case of that you would not like to use the default key `o`.|

This version will create a mapping to search selected text with `search_url` on pressing `search_leader_key` followed by `alias`, except that it adds search alias to omnibar as the normal version. For example, below line

addSearchAliasX('s', 'stackoverflow', 'http://stackoverflow.com/search?q=', 'o');

works like

addSearchAlias('s', 'stackoverflow', 'http://stackoverflow.com/search?q=');
mapkey('os', 'Search Selected with stackoverflow', function() {
searchSelectedWith("http://stackoverflow.com/search?q=");
});
vmapkey('os', 'Search Selected with stackoverflow', function() {
searchSelectedWith("http://stackoverflow.com/search?q=");
});

### remove search alias and its bindings

removeSearchAliasX(alias, search_leader_key, only_this_site_key);

### Omnibar helpers

Omnibar.listWords(<array of words>)
Omnibar.html(<any html snippets>)

### Styling

To change style for link hints:

Hints.style('border: solid 3px #552a48; color:#efe1eb; background: initial; background-color: #552a48;');

To Change style for text hints:

Hints.style("border: solid 8px #C38A22;padding: 1px;background: #e39913", "text");

Change the style of the search marks and cursor:

Visual.style('marks', 'background-color: #89a1e2;');
Visual.style('cursor', 'background-color: #9065b7;');

### Create mapping in vim editor

aceVimMap(lhs, rhs, ctx)

For example,

aceVimMap('jk', '<Esc>', 'insert');

### Properties list

| key | default value | explanation |
Expand All @@ -657,6 +509,7 @@ For example,
| settings.useLocalMarkdownAPI | true | Whether to use [chjj/marked](https://github.com/chjj/marked) to parse markdown, otherwise use github markdown API. |
| settings.focusOnSaved | true | Whether to focus text input after quitting from vim editor. |
| settings.omnibarMaxResults | 10 | How many results will be listed out each page for Omnibar. |
| settings.omnibarHistoryCacheSize | 100 | The maximum of items fetched from browser history. |
| settings.omnibarPosition | "middle" | Where to position Omnibar. ["middle", "bottom"] |
| settings.omnibarSuggestion | false | Show suggestion URLs|
| settings.omnibarSuggestionTimeout | 200 | Timeout duration before Omnibar suggestion URLs are queried, in milliseconds. Helps prevent unnecessary HTTP requests and API rate-limiting. |
Expand Down
7 changes: 0 additions & 7 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Surfingkeys尽量让用户使用键盘进行网页浏览,但有些限制是Goo
* [点命令重复前一个操作](#点命令重复前一个操作)
* [Markdown预览](#markdown预览)
* [截屏](#截屏)
* [mermaid图形生成器](#mermaid图形生成器)
* [PDF阅读器](#pdf阅读器)
* [配置参考](#配置参考)
* [编译](#编译)
Expand Down Expand Up @@ -491,12 +490,6 @@ Surfingkeys默认使用[这个markdown分析器](https://github.com/chjj/marked)

按完以上任一快捷键之后,会弹出你所截取的图片,然后你可以用鼠标(😢)右键单击图片来保存或者复制。

## mermaid图形生成器

[Mermaid](https://github.com/knsv/mermaid) 是一个从文本生成各类图形如类图/时序图的工具。Surfingkeys提供了一个页面,可以从系统剪贴板里读取文本并生成图形,并可以用vim编辑器编辑。

`Ctrl-Alt-d`打开。

## PDF阅读器
为了支持PDF文件,Surfingkeys集成了来自[pdf.js](https://github.com/mozilla/pdf.js)的PDF阅读器。当你用Chrome打开一个PDF文件时,这个PDF阅读器就会打开,这样所有Surfingkeys的按键都可以用了。

Expand Down
15 changes: 15 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"presets": [["@babel/preset-env", { "modules": "commonjs" }], "@babel/preset-typescript"],
"plugins": [
"@babel/plugin-transform-runtime",
[
"module-resolver",
{
"root": ["."],
"alias": {
"src": "./src"
}
}
]
]
}
3 changes: 3 additions & 0 deletions config/jest/afterEnv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { toMatchImageSnapshot } = require('jest-image-snapshot');

expect.extend({ toMatchImageSnapshot });
7 changes: 7 additions & 0 deletions config/jest/globalSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { setupTestServer } from './testServer';

const globalSetup = async () => {
await setupTestServer();
};

export default globalSetup;
7 changes: 7 additions & 0 deletions config/jest/globalTeardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { teardownTestServer } from './testServer';

const globalTeardown = async () => {
await teardownTestServer();
};

export default globalTeardown;
11 changes: 11 additions & 0 deletions config/jest/testServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { spawn } = require('child_process');

export const setupTestServer = async () => {
spawn('npm', [
'run',
'build:testdata'
]);
};

export const teardownTestServer = async () => {
};
Loading

0 comments on commit 4619ee2

Please sign in to comment.