Cian
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: 範例簡報 # 簡報的名稱 tags: presentation # 簡報的標籤 slideOptions: # 簡報相關的設定 theme: moon # 顏色主題 transition: 'fade' # 換頁動畫 # parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg' --- ## とあるノートアプリから始まった色々調査 --- ### Agenda - key event - componsition event - content editable ---- ![](https://i.imgur.com/CEL18cQ.gif) Note: 之所以會想要做這個主題,是因為我很喜歡看到有新的筆記軟體就會跑去玩。而之前玩到一款網頁版的 note app, 發生了這樣的 bug 只要是CJK的文字就會壞掉。因為想知道為什麼開始調查,所以有了這個分享。 ---- Chrome ![](https://i.imgur.com/CEL18cQ.gif) ---- Firefox ![](https://i.imgur.com/xAKcedd.gif) --- ### key event Note: 簡單的入門開始。 因為我在開發和前端相關領域的資歷都很淺,今天講的內容可能過分簡單。如果有任何可以補充的歡迎隨時幫我補充。 ---- #### 大家都知道的 key event 在 browser 中,當按下鍵盤時會觸發三個事件 - keydown - keyup - keypress ---- keydown & keyup ```text The keydown event is fired when a key is pressed. The keydown and keyup events provide a code indicating which key is pressed. ``` Note: - 首先,「keydown」「keyup」比較好理解,keydown可以連續觸發,而 keyup 只會在放開的那一個瞬間觸發。 - 就像是玩遊戲的時候,可以長按集氣,但只會有一個放開的瞬間釋放 ---- Keydown v.s keypress ? ---- MDN: ```text keypress イベントとは異なり、 keydown イベントはすべてのキーにおいて、 文字が入力されるかどうかにかかわらず発生します。 ``` Note: keypress是一種 press ,雖然看起來很像 keydown,但 keypress 只會被「文字按鍵」觸發。 ---- では、問題です。 「はい」を入力するとき、「h」を押すと、 keypressは発火する?しない? <span>[実験しよう](https://www.w3.org/2002/09/tests/keys.html)<!-- .element: class="fragment" data-fragment-index="1" --></span> ---- A: 発火しない ---- bugについての推論 おそらくこちらのイベント処理がちゃんと処理されてないから、 keydownなどで混乱しちゃって、 バグになった Note: ではFirefoxはなんで(ちょっと)うまくいったの? ---- MDN: ```text Firefox 65 から、 keydown および keyup イベントは IME 入力中でも発生するようになり、 CJKT のユーザーのブラウザー間の互換性が向上しました (バグ 354358)。 ``` Note: この内容はおそらく先ほどのfirefoxがそうなにバグらない理由ではないかと。 --- Wait, What? IME? <span><h4>Input Method Editor<!-- .element: class="fragment" data-fragment-index="1" --></h4></span> ---- [Input method editor (インプットメソッドエディター)](https://developer.mozilla.org/ja/docs/Glossary/Input_method_editor) ```text インプットメソッドエディター (IME) は、 テキスト入力のための特殊なユーザーインターフェイスを提供するプログラムです。 インプットメソッドエディターは多くの場面で使用されています。 ``` Note: 也就是說, Firefox 65 から、 keydown および keyup イベントは IME 入力中で発生する。 ---- Reactのソースコードを見ましょう Note: 在寫 React 的時候,我們調用得Event基本上都不是原生的 Event。 React 基本上把 Event 都包起來做了各種處理才交到我們手上。 ---- #### [react/packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js](https://github.com/facebook/react/blob/main/packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js) Composition start ```js /** * Does our fallback best-guess model think this event signifies that * composition has begun? */ function isFallbackCompositionStart( domEventName: DOMEventName, nativeEvent: any, ): boolean { return domEventName === 'keydown' && nativeEvent.keyCode === START_KEYCODE; } ``` ---- ``` START_KEYCODE = 229 ``` ```text If an Input Method Editor is processing key input and the event is keydown, return 229. ``` [keyCode in key events](https://lists.w3.org/Archives/Public/www-dom/2010JulSep/att-0182/keyCode-spec.html) ---- #### [react/packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js](https://github.com/facebook/react/blob/main/packages/react-dom/src/events/plugins/BeforeInputEventPlugin.js) Composition end ```js /** * Does our fallback mode think that this event is the end of composition? */ function isFallbackCompositionEnd( domEventName: DOMEventName, nativeEvent: any, ): boolean { switch (domEventName) { case 'keyup': // Command keys insert or clear IME input. return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1; // const END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space case 'keydown': // Expect IME keyCode on each keydown. If we get any other // code we must have exited earlier. return nativeEvent.keyCode !== START_KEYCODE; case 'keypress': case 'mousedown': case 'focusout': // Events are not possible without cancelling IME. return true; default: return false; } } ``` ---- Composition Events: https://codepen.io/keronscribe/pen/PoErpwm Note: こちらのテスト用のcodepenを見当たって、 でも、よく見ると一番右がdivでできでいるのインプットエリア。 との初心者の発見がありました。 そこで話戻るですが、 先のめっちゃバグるノードで、もうしかしてこれを使って実装されたのと。 --- あたりです ```html [8] <div data-gramm="false" role="textbox" dir="ltr" class="EditorContainer" data-slate-editor="true" data-slate-node="value" contenteditable="true" style="outline: none; white-space: pre-wrap; overflow-wrap: break-word;" </div> ``` --- ### content editable ```text HTMLElement インターフェイスの contentEditable プロパティは、 要素が編集可能かどうかを指定します。 この**列挙属性**には、次の値を設定できます。 ``` ---- ```text この**列挙属性**には、次の値を設定できます。 'true' は、要素の内容が編集可能 (contenteditable) であることを示します。 'false' は、要素が編集できないことを示します。 'inherit' は、要素がその親の編集可能状態を継承することを示します。 ``` ---- content editable を使っている editor - GitHub も使っている [CodeMirror](https://github.com/codemirror/CodeMirror/blob/22e9d4f6ce451196803898be1bad859567df6107/src/input/ContentEditableInput.js#L19) - このスライドを作成する環境の[HackMD](https://hackmd.io/) - 最近ちょっと話題になってる[lexical](https://github.com/facebook/lexical/blob/4e57eb8d7e0ca00fe998f02b9dd3efaaef858a2e/packages/lexical-react/src/LexicalContentEditable.jsx#L94) ---- [lexical Rich text editor ](https://playground.lexical.dev/)は本当に綺麗と思います。 Note: Reactも使えるので興味がある方ぜひ ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully