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

CRLF not processed when pasting in code block #3270

Open
1 task done
morecup opened this issue May 22, 2022 · 2 comments · May be fixed by #3272
Open
1 task done

CRLF not processed when pasting in code block #3270

morecup opened this issue May 22, 2022 · 2 comments · May be fixed by #3272

Comments

@morecup
Copy link

morecup commented May 22, 2022

Description

  • Can you reproduce the issue?

Steps to reproduce

  1. Copy a piece of code for CRLF
  2. Paste into code block
    image
  3. Use enter after crlf string
    image
  4. Dislocation occurs

Versions

  • MarkText version: 0.17.1
  • Operating system: win10
@morecup morecup changed the title In configuration,EndOfLine default in win10 is 'lf' .Should be 'crlf'. Dislocation occurs May 22, 2022
@morecup
Copy link
Author

morecup commented May 23, 2022

我调试了源码,发现在代码块里粘贴的时候是以原格式粘贴,只有当做一个删除或者其他操作时才会把/r/n转为/n,我认为粘贴时应该对/r/n进行处理。
I debugged the source code and found that when pasting in the code block, it is pasted in the original format. Only when it is used as a deletion or other operation will /r/n be converted to /n. I think /r/n should be processed when pasting.
Problem code:
src/muya/lib/contentState/pasteCtrl.js

if (startBlock.type === 'span' && startBlock.functionType === 'codeContent') {
      const blockText = startBlock.text
      const prePartText = blockText.substring(0, start.offset)
      const postPartText = blockText.substring(end.offset)
      startBlock.text = prePartText + text + postPartText
      const { key } = startBlock
      const offset = start.offset + text.length
      this.cursor = {
        start: { key, offset },
        end: { key, offset }
      }

      return this.partialRender()
    }

@morecup morecup changed the title Dislocation occurs CRLF not processed when pasting May 23, 2022
@morecup morecup changed the title CRLF not processed when pasting CRLF not processed when pasting in code block May 23, 2022
@morecup
Copy link
Author

morecup commented May 23, 2022

fix code:

startBlock.text = prePartText + text.replace(/\r\n/g, '\n') + postPartText

morecup pushed a commit to morecup/marktext that referenced this issue May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant