3
4

More than 1 year has passed since last update.

(2021年7月)Visual Studio Codeで罫線文字の図形を描く

Last updated at Posted at 2021-07-01

はじめに

Visual Studio Codeで罫線文字の図形を描く拡張機能を作成しました。
Visual Studio Codeの拡張機能から"boxdraw"で検索してください。

(2021/07/01) 開発したばかりの機能です。不具合、要望があればお知らせください。

Boxdraw

罫線文字で図形を描くための拡張機能です。

boxdraw

機能

罫線文字および矢印で図形を描けます。
罫線文字以外にブロック文字でも図形を描けます。

使い方

共通

共通機能 キー
罫線モードの有効/無効の切り替え ctrl + alt + m

罫線モード

機能 キー
罫線文字の描画 ctrl + 矢印キー
矢印文字の描画 ctrl + alt + 矢印キー
文字のクリア ctrl + shift + 矢印キー
描画モード(罫線+矢印/ブロック)の切り替え ctrl + alt + b
カーソルの上下移動 上下矢印キー

留意事項

  • vscode
    • 設定
      • 日本語フォントは等幅のものにしてください。
      • スペースによるインデントにしてください。
    • 制限
      • マルチカーソルには対応していません。
  • boxdraw-extension
    • 仕様
      • cursorUp/cursorDown
        • 罫線文字が内部的に半角1文字で計算されていることによるカーソルの上下移動時の左右のがたつきを抑制します。
      • cursorDown
        • 最下行では行末に移動する動きは実装していません。
      • cursorUpSelect/cursorDownSelect
        • 選択領域の制御は実装していません。

vscodeの全角文字の内部実装

vscodeでは多くの全角記号が内部的には半角文字として扱われています。
少なくとも0x0000-0x2e7fの範囲の文字は画面上の表示幅が2桁であっても内部的には1桁で計算が行われています。
詳細は https://github.com/microsoft/vscode/blob/main/src/vs/base/common/strings.ts のisFullWidthCharacter()をご覧ください。

https://github.com/microsoft/vscode/blob/main/src/vs/base/common/strings.ts:

export function isFullWidthCharacter(charCode: number): boolean {
	// Do a cheap trick to better support wrapping of wide characters, treat them as 2 columns
	// http://jrgraphix.net/research/unicode_blocks.php
	//          2E80 — 2EFF   CJK Radicals Supplement
	//          2F00 — 2FDF   Kangxi Radicals
	//          2FF0 — 2FFF   Ideographic Description Characters
	//          3000 — 303F   CJK Symbols and Punctuation
	//          3040 — 309F   Hiragana
	//          30A0 — 30FF   Katakana
	//          3100 — 312F   Bopomofo
	//          3130 — 318F   Hangul Compatibility Jamo
	//          3190 — 319F   Kanbun
	//          31A0 — 31BF   Bopomofo Extended
	//          31F0 — 31FF   Katakana Phonetic Extensions
	//          3200 — 32FF   Enclosed CJK Letters and Months
	//          3300 — 33FF   CJK Compatibility
	//          3400 — 4DBF   CJK Unified Ideographs Extension A
	//          4DC0 — 4DFF   Yijing Hexagram Symbols
	//          4E00 — 9FFF   CJK Unified Ideographs
	//          A000 — A48F   Yi Syllables
	//          A490 — A4CF   Yi Radicals
	//          AC00 — D7AF   Hangul Syllables
	// [IGNORE] D800 — DB7F   High Surrogates
	// [IGNORE] DB80 — DBFF   High Private Use Surrogates
	// [IGNORE] DC00 — DFFF   Low Surrogates
	// [IGNORE] E000 — F8FF   Private Use Area
	//          F900 — FAFF   CJK Compatibility Ideographs
	// [IGNORE] FB00 — FB4F   Alphabetic Presentation Forms
	// [IGNORE] FB50 — FDFF   Arabic Presentation Forms-A
	// [IGNORE] FE00 — FE0F   Variation Selectors
	// [IGNORE] FE20 — FE2F   Combining Half Marks
	// [IGNORE] FE30 — FE4F   CJK Compatibility Forms
	// [IGNORE] FE50 — FE6F   Small Form Variants
	// [IGNORE] FE70 — FEFF   Arabic Presentation Forms-B
	//          FF00 — FFEF   Halfwidth and Fullwidth Forms
	//               [https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms]
	//               of which FF01 - FF5E fullwidth ASCII of 21 to 7E
	// [IGNORE]    and FF65 - FFDC halfwidth of Katakana and Hangul
	// [IGNORE] FFF0 — FFFF   Specials
	charCode = +charCode; // @perf
	return (
		(charCode >= 0x2E80 && charCode <= 0xD7AF)
		|| (charCode >= 0xF900 && charCode <= 0xFAFF)
		|| (charCode >= 0xFF01 && charCode <= 0xFF5E)
	);
}

謝辞

  • Boxdraw の基本的なアイデアは xyzzy の boxdraw.l を参考にしています。
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4