移动和消失的代码行;Eclipse 的 XML 编辑器的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10030727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Moving and vanishing lines of code; trouble with Eclipse's XML Editor
提问by Sam
Sometimes my code moves on its own or just disappears in the Eclipse XML editor.
有时我的代码会自行移动或在 Eclipse XML 编辑器中消失。
When I highlight the affected code, the highlighted lines try to correct themselves. But when I scroll or drag the mouse in the opposite direction the code shifts again. In essence I will have repeating, missing, andbroken lines of code being displayed from an otherwise error free file. The files affected docompile and if I close / re-open them this problem goes away, for the moment. Any ideas on what's happening?
当我突出显示受影响的代码时,突出显示的行会尝试自行纠正。但是当我向相反方向滚动或拖动鼠标时,代码再次移动。本质上,我将从其他无错误文件中显示重复、丢失和断行的代码行。受影响的文件会编译,如果我关闭/重新打开它们,这个问题就暂时消失了。关于发生了什么的任何想法?
Addition:Jeff Axelrodprovided a link to a new bug reportwith Google.
补充:Jeff Axelrod提供了一个指向Google的新错误报告的链接。
采纳答案by Tor Norbye
This bug is (finally) fixed in ADT 21. The fix is now available in ADT 21 Preview 9, posted a few minutes ago, here: https://android-review.googlesource.com/#/c/44936/1
此错误已(最终)在 ADT 21 中修复。该修复程序现已在几分钟前发布的 ADT 21 预览版 9 中提供,此处:https: //android-review.googlesource.com/#/c/44936/1
The reason you get weird visual artifacts is that if a file contains broken DOS line endings (multiple carriage returns without a newline for each carriage return), Eclipse gets very confused. That's Eclipse issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=375421.
您得到奇怪的视觉工件的原因是,如果文件包含损坏的 DOS 行结尾(多个回车,每个回车没有换行符),Eclipse 会变得非常困惑。那是 Eclipse 问题https://bugs.eclipse.org/bugs/show_bug.cgi?id=375421。
There are two parts to the fix: (1) First, ADT was fixed such that it no longer introduces these \r\r sequences into the document. This makes sure that you don't get new documents which triggers the weird editing behavior, but it does not retroactively fix older documents with these line endings, so if you open them, you still get weird editing behavior.
修复有两个部分: (1) 首先,ADT 已修复,不再将这些 \r\r 序列引入文档。这确保您不会获得触发奇怪编辑行为的新文档,但它不会追溯修复具有这些行结尾的旧文档,因此如果您打开它们,您仍然会遇到奇怪的编辑行为。
(2) Second, there's a new lint check which looks for broken line endings in documents. This runs incrementally, so if you edit an XML file which has this problem, ADT will add an error marker for this problem -- along with a quickfix to perform surgery on the document to fix it.
(2) 其次,有一个新的 lint 检查,用于查找文档中的断行结尾。这会以增量方式运行,因此如果您编辑存在此问题的 XML 文件,ADT 将为此问题添加一个错误标记 -- 以及对文档进行修复以修复它的快速修复程序。
In short: Get ADT 21 Preview 9; run Lint on your projects and look for any complaints about files containing broken line endings, and if it finds any, apply the quickfix. From now on, further edits with the layout editor should keep the files consistently formatted.
简而言之:获取 ADT 21 Preview 9;在您的项目上运行 Lint 并查找有关包含断行结尾的文件的任何投诉,如果找到任何投诉,请应用 quickfix。从现在开始,使用布局编辑器进一步编辑应该保持文件格式一致。
FYI, the relevant fix is here: https://android-review.googlesource.com/#/c/44936/
仅供参考,相关修复在这里:https: //android-review.googlesource.com/#/c/44936/
Instructions for easily updating SDK Tools and the Eclipse ADT plugin are here: http://tools.android.com/preview-channel
轻松更新 SDK 工具和 Eclipse ADT 插件的说明在此处:http: //tools.android.com/preview-channel
-- Tor (from the Android tools team)
-- Tor(来自 Android 工具团队)
回答by SylvainL
After some tests, I have found that the option "Automatically format the XML edited by the visual layout editor" (in Preferences | Android | Editors) might be the culprit here.
经过一些测试,我发现选项“自动格式化由可视化布局编辑器编辑的 XML”(在 Preferences | Android | Editors 中)可能是这里的罪魁祸首。
With my tests, I've found that changing a property (such as the layout_gravity) while in Graphical Layout design mode always screw up the visual display of the file when I go back to the XML (text) mode when this option is ON but that I have no problem when it's off.
通过我的测试,我发现在图形布局设计模式下更改属性(例如 layout_gravity)总是会在打开此选项时返回 XML(文本)模式时破坏文件的视觉显示,但是当它关闭时我没有问题。
If you want to format the XML upon your return from the Graphical Layout design mode, simply use the shortcut Ctrl+Shift+F. Also, I didn't see any problem with using the option "Format on Save"; even when I use it in the Graphical Layout mode; so you can use Ctrl+Sinstead while you're still in the Graphical Layout mode to both save and format your XML.
如果您想在从图形布局设计模式返回时格式化 XML,只需使用快捷键Ctrl+ Shift+ F。另外,我没有发现使用“格式保存”选项有任何问题;即使我在图形布局模式下使用它;因此您可以在仍处于图形布局模式时使用Ctrl+S来保存和格式化您的 XML。
I've tried other editors options like "Show range indicator" or "Use characters to show changes in vertical ruler" but I didn't see any difference in behavior with activating or de-activating these options.
我尝试过其他编辑器选项,如“显示范围指示器”或“使用字符显示垂直标尺的变化”,但我没有看到激活或取消激活这些选项的行为有任何差异。
Finally, to correct the visual display of the file when it's corrupt; I found that using the shortcut: Ctrl+A, Ctrl+C, Ctrl+Vis a little easier than closing/reopening the file. This is equivalent to making a Select All, Copy, Paste; effectively copying the whole XML file over itself.
最后,纠正文件损坏时的视觉显示;我发现使用快捷方式:Ctrl+ A, Ctrl+ C, Ctrl+V比关闭/重新打开文件要容易一些。这相当于进行全选、复制、粘贴;有效地将整个 XML 文件复制到自身之上。
回答by Dvide Leprechaun
EDIT:contain faster method, so it was bring to top:
编辑:包含更快的方法,所以它被带到了顶部:
Ctrl+F-> fill like that:
Ctrl+ F-> 像这样填充:
- "Find" "\r\r\n"
- "Replace" "\r\n"
- Switch "Regular expression"to ON
- hit the "Replace all"button
- Ctrl+A
- deselect text.
- be happy =)
- "查找" "\r\r\n"
- "替换" "\r\n"
- 将“正则表达式”切换为ON
- 点击“全部替换”按钮
- Ctrl+A
- 取消选择文本。
- 快乐=)
Original was here:Just don't hide that issue, if you may fix it. Some times even closing the XML file didn't help.
原文在这里:只要你能解决这个问题,就不要隐藏它。有时甚至关闭 XML 文件也无济于事。
For fix it let's look at the reason of it. First of all Turn On "Show Whitespace Characters" (Window > Preferences > General > Editors > Text Editors > Show whitespace characters)
为了修复它,让我们看看它的原因。首先打开“显示空白字符”(Window > Preferences > General > Editors > Text Editors > Show whitespace characters)
Then back to your XML-file.
然后返回到您的 XML 文件。
In scaled image you may see the difference of "\n"-symbol colors;
在缩放的图像中,您可能会看到“\n”-符号颜色的差异;
then just put cursor to that symbol, which is more dark.
然后只需将光标放在那个更暗的符号上。
look, two lines was selected 0o... that's may be the reason!
看,两行被选择了0o...这可能是原因!
so just delete it, and press "Enter" or "Return" button for add "\n" symbol.
Hope it help you.
所以只需删除它,然后按“Enter”或“Return”按钮添加“\n”符号。
希望对你有帮助。
also you may find the other symbol of endline:
您还可以找到端线的另一个符号:
Just delete it too, and your XML will have a great look!
也只需将其删除,您的 XML 就会看起来很棒!
P.S. sorry for hyperlinks, i'm newbie and on SO i can't upload image or more than 2 links. so hope you'll get the point without additional pictures ;)
PS对不起超链接,我是新手,所以我不能上传图片或超过2个链接。所以希望你能在没有额外图片的情况下明白这一点;)
P.P.S. Thx to guy who vote up, now i can provide this with images.
PPS 感谢投票的人,现在我可以提供图像。
回答by Vaiden
Still experiencing this bug on Juno (Eclipse 4.2.0, ADT r20).
在 Juno(Eclipse 4.2.0,ADT r20)上仍然遇到这个错误。
My fix: Go to Window -> Preferences -> Android -> Editors. I have both "Format XML using the standard Android XML..."and "Use Eclipse settings for indentation...."checked. This solved the problem for me.
我的修复:转到窗口 -> 首选项 -> Android -> 编辑器。我已经选中了“使用标准 Android XML 格式化 XML...”和“使用 Eclipse 设置进行缩进...”。这为我解决了这个问题。
回答by pcs
I had the same difficulty and finally found the solution: Right click in the editor, select Source/Cleanup Document
.
我遇到了同样的困难,终于找到了解决方案:在编辑器中右键单击,选择Source/Cleanup Document
.
回答by Ewoks
When this bug appears with new versions of ADT(which are mandatory for fixing and where bug should not appear often) just use Lint tool to fix it..
当这个错误随着新版本的 ADT出现时(这是修复的必要条件,并且错误不应该经常出现),只需使用 Lint 工具来修复它。
Find it in Lint warnings and click yellow bulbicon in upper right corner of that Lint warnings list..
在 Lint 警告中找到它,然后单击Lint 警告列表右上角的黄色灯泡图标。
Hope it will help somebody
希望它会帮助某人
回答by Stephen
I had the same issue. The following steps were the solution. Link suggest its worked for others.
我遇到过同样的问题。以下步骤是解决方案。链接建议它对其他人有用。
- Go to Preferences -> keys
- Unbind copy, paste, and cut (hit "apply", then "ok")
- repeat step 1
- Restore unbound commands from step 2 (I didn't restore cut, but I'm sure you'd be fine)
- 转到首选项 -> 键
- 取消绑定复制、粘贴和剪切(点击“应用”,然后点击“确定”)
- 重复步骤 1
- 从第 2 步恢复未绑定的命令(我没有恢复 cut,但我相信你会没事的)
Notice there are 2 bindings for each of the 3 commands
请注意,3 个命令中的每一个都有 2 个绑定
- Unbind secondary function for both copy and paste (leave ctl+c/ctl+v [copy/paste] bound)
- 解除复制和粘贴的辅助功能(保留 ctl+c/ctl+v [copy/paste] 绑定)
At this point you should only have 2 bindings set to perform copy/paste (i.e., ctl+c/ctl+v)
此时,您应该只设置 2 个绑定来执行复制/粘贴(即 ctl+c/ctl+v)
- Hit apply -> OK
- 点击应用 -> 确定
This solution was found here.
这个解决方案是在这里找到的。