Skip to content

Commit

Permalink
support shift+enter ; tag 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Sep 24, 2023
1 parent a9a49de commit 8ac704d
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 219 deletions.
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
Loading

0 comments on commit 8ac704d

Please sign in to comment.