Skip to content

Commit

Permalink
textarea内でtab key使ってインデントできるようにした (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO authored Dec 18, 2022
1 parent ac731a1 commit f291ff0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/gtree-wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ deploy: confirm tinybuild
cleancss -o ../../docs/toast.css toast.css
uglifyjs main.js --compress drop_console=true -o ../../docs/main.js
uglifyjs toast.js --compress drop_console=true -o ../../docs/toast.js
uglifyjs tab.js --compress drop_console=true -o ../../docs/tab.js
uglifyjs wasm_exec.js --compress drop_console=true -o ../../docs/wasm_exec.js
cp index.html service_worker.js robots.txt sitemap.xml ../../docs
mv main.wasm ../../docs
2 changes: 1 addition & 1 deletion cmd/gtree-wasm/confirm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

echo -n "service_worker.js の CACHE_VERSION 変数を更新しましたか? [y/N]: "
echo -n "service_worker.js の CACHE_VERSION 変数の変更/ 新規作成したjsファイルを urlsToCache に追加しましたか? [y/N]: "
read ANS

case $ANS in
Expand Down
1 change: 1 addition & 0 deletions cmd/gtree-wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h1 class="text-3xl font-bold">
</div>

<script src="toast.js"></script>
<script src="tab.js"></script>

<script>
// register service_worker.js
Expand Down
1 change: 0 additions & 1 deletion cmd/gtree-wasm/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ const copyToClipboard = () => {
const clipboard = window.navigator.clipboard;
clipboard.writeText(tree.innerHTML);
};

3 changes: 2 additions & 1 deletion cmd/gtree-wasm/service_worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// copied by https://laboradian.com/create-offline-site-using-sw/

// TODO: ファイル変更したらCACHE_VERSIONを変えてデプロイすること
const CACHE_VERSION = 'v1.1.3';
const CACHE_VERSION = 'v1.1.4';
const CACHE_NAME = `${registration.scope}!${CACHE_VERSION}`;

// キャッシュするファイルをセットする
Expand All @@ -12,6 +12,7 @@ const urlsToCache = [
'toast.css',
'main.js',
'toast.js',
'tab.js',
'wasm_exec.js',
];

Expand Down
19 changes: 19 additions & 0 deletions cmd/gtree-wasm/tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ref: http://www.webclap-dandy.com/?category=Programing&id=5
const tabKey = 9;
const spaces = ' ';
const onTabKey = (e) => {
if (e.keyCode != tabKey){ return; };

e.preventDefault();

const cursor = e.target;
const currStr = String(cursor.value);

const position = cursor.selectionStart;
const left = currStr.substring(0, position);
const right = currStr.substring(position, currStr.length);

cursor.value = left + spaces + right;
cursor.selectionEnd = position + spaces.length;
};
document.getElementById('in').onkeydown = (e) => onTabKey(e);
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h1 class="text-3xl font-bold">
</div>

<script src="toast.js"></script>
<script src="tab.js"></script>

<script>
// register service_worker.js
Expand Down
3 changes: 2 additions & 1 deletion docs/service_worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// copied by https://laboradian.com/create-offline-site-using-sw/

// TODO: ファイル変更したらCACHE_VERSIONを変えてデプロイすること
const CACHE_VERSION = 'v1.1.3';
const CACHE_VERSION = 'v1.1.4';
const CACHE_NAME = `${registration.scope}!${CACHE_VERSION}`;

// キャッシュするファイルをセットする
Expand All @@ -12,6 +12,7 @@ const urlsToCache = [
'toast.css',
'main.js',
'toast.js',
'tab.js',
'wasm_exec.js',
];

Expand Down
1 change: 1 addition & 0 deletions docs/tab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f291ff0

Please sign in to comment.