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 shift+enter ; CI script update #24

Merged
merged 2 commits into from
Oct 1, 2023
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 20
registry-url: https://registry.npmjs.org/

- run: yarn && yarn compile
Expand Down
19 changes: 5 additions & 14 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,19 @@ jobs:
upload-assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v2

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
- uses: actions/setup-node@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
node-version: 20
cache: 'yarn'

- run: yarn && yarn vite build --base=./
name: Build web assets

- name: Deploy to server
id: deploy
uses: Pendect/action-rsyncer@v1.1.0
uses: Pendect/action-rsyncer@v2.0.0
env:
DEPLOY_KEY: ${{secrets.rsync_private_key}}
with:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mvc-works/codearea",
"version": "0.0.3",
"version": "0.0.4",
"description": "Web app scaffold based on Webpack",
"main": "lib/codearea.js",
"scripts": {
Expand All @@ -13,8 +13,8 @@
"workflow"
],
"devDependencies": {
"typescript": "^4.4.3",
"vite": "^2.5.8"
"typescript": "^5.2.2",
"vite": "^4.4.9"
},
"dependencies": {},
"repository": {
Expand Down
37 changes: 35 additions & 2 deletions src/codearea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,33 @@ let triggerInput = function (element: HTMLTextAreaElement) {
bubbles: true,
cancelable: true,
});
return element.dispatchEvent(event);
element.dispatchEvent(event);
};

interface TextInfo {
/** row */
row: number;
/** column */
col: number;
/** all lines */
all: string[];
/** selection start at row */
ar: number;
/** selection start at column */
ac: number;
/** is select start at line start */
as: boolean;
/** is select start at line end */
ae: boolean;
/** selection end at row */
br: number;
/** selection end at column */
bc: number;
/** is select end at line start */
bs: boolean;
/** is select end at line end */
be: boolean;
/** no selection, just same caret */
same: boolean;
}

Expand Down Expand Up @@ -90,7 +102,8 @@ let write_text = function (
}
}
// o '4: ', ar, ac, br, bc, obj.bc
target.value = arr.join("\n");
let newText = arr.join("\n");
target.value = newText;
target.selectionStart = set_position(arr, ar, ac);
target.selectionEnd = set_position(arr, br, bc);
triggerInput(target);
Expand Down Expand Up @@ -328,6 +341,22 @@ let key_enter = function (target: HTMLTextAreaElement, event: Event) {
}
};

// enter only, consider last line and
let key_shift_enter = function (target: HTMLTextAreaElement, event: Event) {
event.preventDefault();
let caret = wrap_text(target);
let { all, ar, ac } = caret;
if (caret.same) {
all = all.slice(0, +ar + 1 || 9e9).concat(all.slice(ar));
let line = all[ar];
let spaces = line.match(/^\s*/)[0];
all[ar] = spaces;
ac = spaces.length;
ar = ar;
return write_text(target, { all, ac, ar });
}
};

// press backspace at head, last line if empty, delete it
let key_backspace = function (target: HTMLTextAreaElement, event: Event) {
var ac, all, ar, caret, n, pair;
Expand Down Expand Up @@ -537,6 +566,10 @@ let call_shortcut = {
9: function (target: HTMLTextAreaElement, event: Event) {
return key_tab(target, event);
},

"shift 13": function (target: HTMLTextAreaElement, event: Event) {
return key_shift_enter(target, event);
},
13: function (target: HTMLTextAreaElement, event: Event) {
return key_enter(target, event);
},
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lib": ["es2016", "dom"],
"types": [],
"baseUrl": "./example/",
"importsNotUsedAsValues": "preserve",
"verbatimModuleSyntax": true,
"plugins": [
{
"name": "typescript-styled-plugin"
Expand Down
Loading