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

windows上代码块里复制的代码的换行符不是\r\n #10596

Closed
3 tasks done
iamqiz opened this issue Mar 13, 2024 · 19 comments
Closed
3 tasks done

windows上代码块里复制的代码的换行符不是\r\n #10596

iamqiz opened this issue Mar 13, 2024 · 19 comments

Comments

@iamqiz
Copy link
Contributor

iamqiz commented Mar 13, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

我的代码块里有个window路径,双击选中整行之后粘贴到explorer.exe地址栏里提示找不到路径,
经过研究发现原因是其换行符是\n而不是window换行符\r\n
比如:
代码块里有一行内容为
C:\Windows\System32
三击选中并复制整行
验证代码:
powershell

// 获取长度:返回20
[System.Windows.Forms.Clipboard]::GetText().Length
// 检测剪贴板文本是否以\r\n结尾, 返回false
[System.Windows.Forms.Clipboard]::GetText().EndsWith("`r`n")
检测剪贴板文本是否以2\n结尾,返回true
[System.Windows.Forms.Clipboard]::GetText().EndsWith("2`n")

Expected result

期望换行符根据平台不同进行设置

Screenshot or screen recording presentation

No response

Version environment

- Version: v3.0.2
- Operating System:  win10
- Browser (if used):

Log file

`

More information

No response

@88250
Copy link
Member

88250 commented Mar 14, 2024

抱歉,这个不支持,编辑器引擎 Lute 在词法分析阶段会统一将 \r\n 识别为 \n。

@88250 88250 closed this as completed Mar 14, 2024
@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

@88250 @Vanessa219 分析时将\r\n和\n都识别为 \n, 没问题
在复制时, 如果操作系统是window,则将\n换行符替换为\r\n, 这个机制在前端就能实现吧?,不受引擎影响吧?

@88250
Copy link
Member

88250 commented Mar 28, 2024

Lute 词法分析的时候替换的。

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

在前端复制的时候,还要调用lute来替换? 复制一次解析一次???

@88250
Copy link
Member

88250 commented Mar 28, 2024

是的。

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

@88250 @Vanessa219 我看代码了,纯文本可以在lute处理后进行replace, 如下图
Clip_2024-03-28_21-03-31

代码块就是纯文本,意味着也可以替换换行符
对吧?

@88250
Copy link
Member

88250 commented Mar 28, 2024

只是处理复制出来的地方的话应该可以的。

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

对的,我的意思就是"复制出来", 而不是粘贴进去 @88250 @Vanessa219

@88250
Copy link
Member

88250 commented Mar 28, 2024

@88250 @Vanessa219 分析时将\r\n和\n都识别为 \n, 没问题 在复制时, 如果操作系统是window,则将\n换行符替换为\r\n, 这个机制在前端就能实现吧?,不受引擎影响吧?

但是你上面说的这一点感觉有风险,如果本来就是 \n 怎么处理?

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

@88250 粘贴到代码块时,\r\n不就会被替换成\n了吗 ? 那复制时,对于 思源来说就已经分不清\n原来是\n还是\r\n了呀

@88250
Copy link
Member

88250 commented Mar 28, 2024 via email

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 28, 2024

@88250 在设置里增加个2选项:
1 粘贴代码到代码块时是否将\r\n替换成\n
2 复制时使用哪种换行符? \n 或\r\n

类似git 的crlf选项

@88250
Copy link
Member

88250 commented Mar 28, 2024 via email

@iamqiz
Copy link
Contributor Author

iamqiz commented Mar 29, 2024

@88250 我觉得这种基础的功能应该由思源来实现, 插件实现的话,一没copy event,二是即便有,插件的copy事件和思源的copy事件可能会冲突
考虑到复制出的代码可能会被粘贴到git仓库文件内,而复制出的换行符只有\n一种情况,那么就有可能导致换行符问题
我倾向于原汁原味保留原来的换行符,即\r\n粘贴进去不被替换为\n ; 这样的话复制出来也不用考虑替换了

@88250
Copy link
Member

88250 commented Mar 29, 2024

粘贴输入部分估计是改不了了,目前只能考虑复制输出的部分用插件。

@iamqiz
Copy link
Contributor Author

iamqiz commented Apr 1, 2024

@88250 为什么改不了?
用插件,难度大多了,一没copy event,二是即便有,插件的copy事件和思源的copy事件可能会冲突 (实在不想把我的话再重复一遍)

@88250
Copy link
Member

88250 commented Apr 1, 2024

Lute 改这部分难度有点大,你有空的话可以试试。

@iamqiz
Copy link
Contributor Author

iamqiz commented Apr 4, 2024

@88250 没时间研究lute
你当时写lute把\r\n替换为\n应该是单独的一段代码吧? 如果是,删掉不就行了吗
我的理解是代码块解析,只需要解析开头和结尾的```xx或``` ,中间的部分就是纯文本,解析需要很复杂吗?

@88250
Copy link
Member

88250 commented Apr 5, 2024

先建个 issue,后面评估看看 88250/lute#204

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

No branches or pull requests

2 participants