推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
xiaoming1992

\r\n 造成的 bug

  •  
  •   xiaoming1992 · Jul 1, 2020 · 2025 views
    This topic created in 2144 days ago, the information mentioned may be changed or developed.

    想要用 electron 实现功能:拖拽字符串或者文件(夹)到一个 dropable element 上,在 onDrop 事件中分割字符串,得到合法文件(夹)路径

    <Button onDrop={(e) => {
    	e.preventDefault()
    
    	if (/* is file */) {
        	setPaths(f.path)
        } else if (/* is string */) {
        	setPaths(inputStr.split("\n"))
        }
    }>dropable elem</Button>
    

    结果在实践中,拖拽文本时符合预期,拖拽系统资源管理器中的多个文件(夹)也正常,可唯独直接从 vscode 的资源管理器中拖拽多个文件时,总是错误,无论我怎么处理,在 setPaths 之后判断路径是否存在时,总是报错,无论拖拽几个文件(夹),总是只能识别出一个文件存在,其他文件都报不存在。

    最开始怀疑是判断程序运行在 renderer 中的问题,可是放到 main 中也一样。最后想了想,难道是因为\r\n 的问题?试了试,果然,vscode 拖拽多个文件时,得到的字符串的换行符并不是\n,而是\r\n 。。。

    1 replies    2020-07-02 09:55:02 +08:00
    lijialong1313
        1
    lijialong1313  
       Jul 2, 2020
    好像是因为 win10 会自动适应了,你试试看 win7 这类应该估计都是 /r/n
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4293 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 05:19 · PVG 13:19 · LAX 22:19 · JFK 01:19
    ♥ Do have faith in what you're doing.