Paste hell - how to stop Idea from inserting \n in strings?
Hi folks,
I'm trying to figure out how to stop Idea from inserting \n in strings which span multiple lines. Breaking up the string with "" + "" is fine, but inserting "\n" + "" is just wrong as now its breaking up stuff that is supposed to be on the same line.
Please sign in to leave a comment.
I think the current behaviour is pretty correct. If you press ]]> inside a string the string is separated without inserting a newline. But if you paste a string which contains already newlines then these newlines are also inserted. This may be wrong in some cases, but most of the time it's exactly what I want.
It annoys me a lot that Idea now escapes escape character on paste - the
result is that I can't paste any string with escape characters in it. I wish
this mode was optional
"Gregory Pierce" <no_mail@jetbrains.com> wrote in message
news:22529380.1064344219016.JavaMail.itn@is.intellij.net...
>
which span multiple lines. Breaking up the string with "" + "" is fine, but
inserting "\n" + "" is just wrong as now its breaking up stuff that is
supposed to be on the same line.
Martin Fuhrer wrote:
I agree ... knowing IDEA's behaviour - problems can be easily avoided.
Alex Roytman wrote:
Same here. My suggestion is basically to put the escaping into a seperate
undo step so that I can undo it independently from the paste. I think that
would work fairly well in most cases.
I've mentioned this in these SCRs that deal with string paste problems but didn't
file a 'real' one for it yet.
http://www.intellij.net/tracker/idea/viewSCR?publicId=16849
http://www.intellij.net/tracker/idea/viewSCR?publicId=11689
Sascha
Sascha Weinreuter wrote:
>>It annoys me a lot that Idea now escapes escape character on paste - the
>>result is that I can't paste any string with escape characters in it. I wish
>>this mode was optional
That is essentially what M$ Word does when it automatically changes something.
For instance, with some commonly mistyped words it will autocorrect for you.
Sometimes the word is mispelled on purpose (i.e. documenting common mistakes in
another document). Entering the undo command (Ctrl-Z) will undo the autocorrect
the first time, and a second time will undo the typing.
No, the behavior is wrong. There were no special characters in the original string - there shouldn't be any in the final string unless I ask for them. There mere fact that I have to go behind Idea and remove them suggests that this behavior at best needs to be an option that can be removed in the Options.
Idea in the past has never gotten in the way of getting work done until now.
I would be more inclined to suggest that it paste the text as normal since that is what every application EXCEPT Idea does and add an intention for strings that span multiple lines such that you can have it break the string as "" + "" or "\n" + "".
The strings I'm dealing with in particular are very long URLs that simply won't fit on one line going into an HTML generator. I cannot express in words how painful it has been to debug when Idea keeps inserting characters into the URLs that I need to post!
Gregory Pierce wrote:
Well, I agree that for some users the - let's call it "Smart Paste" - should be
optional because it is non-standard behavior. On the other hand, IDEA
already introduced some non-standard concepts that work pretty well,
so I think it there's no real need to make everything optional as long as it
doesn't interfere with what a user intends to do.
For me I'd say that in the majority of cases (at least for me) the escaping is
what I'd expect (if it works right). In all other cases it is a real pain though
and the ability to undo IDEA's smart action would suffice for me.
The intention to break strings that contain newline sequences is independent
from that because it would be useful for any kind of strings, not just pasted
ones.
Sascha
Agreed.
Requests filed:
Smart Paste & Undo: http://www.intellij.net/tracker/idea/viewSCR?publicId=16943
Split String Intention: http://www.intellij.net/tracker/idea/viewSCR?publicId=16942
Sascha
Well, it seems I have the things completely messed in my head.
We can do "Smart Paste" undoable but this is not what Gregory wants!
Let see a sample case:
Content in the clipboard:
Link line1 Link line2 Link line3 ]]>
Pasting into System.out.println("|");
where | denotes caret position.
Smart version:
Link line1\n" + "Link line2\n" + "Link line3\n" + "" ]]>
Normal version:
Link line1 Link line2 Link line3 " ]]>
Which is syntactically incorrect all highlighted in red and needs IMO much
more manual modification than just removing unneded \n's
Please note the intention behind "smart" paste is simple as 1, 2, 3: If
pasted into System.out.print("|") one will print out exactly the same
content as have been pasted!
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:bksem0$b1a$1@is.intellij.net...
>
since that is what
span multiple
"".
>
simply won't fit on one
it has been to
post!
>
should be
it
>
escaping is
though
>
independent
pasted
>
>
>
Maxim Shafirov (JetBrains) wrote:
Oops, yes you're right. But this is IMHO a second aspect of Smart Paste that
converts hard newlines into \n sequences and is independent from the auto-
escaping.
My primary concern was that dealing with already escaped strings is pretty
painful right now and would directly benefit from a seperate undo. I even think
Smart Paste involves three steps:
1. Paste
2. Convert newlines from clipboard into \n
3. Escape protected characters
Step 3 should be undoable and 1+2 together because that exactly resembles the
contents of the clipboard.
Does this sound reasonable or am I dead wrong :) ?
Sascha
1. Seems you've missed surrounding each new pasted line with '" " +'
pattern in your 1, 2, 3 list.
2. Am I right you're suggesting completely ignore newline characters in
clipboard when pasting? This way it gonna be a single long line with no idea
for intention on where to break it or insert \n chars. Let's be a bit more
formal in this discussion.
Well, as far as I understand there are cases when current IDEA's behaviour
is oversmart and annoying and it actually doing something it shouldn't do in
user's opinion.
So would you please provide some samples of such undesired behavior so we
can decide what actually needed in this case and probably find a common
denominator of all cases or some sequence of undoable actions that will
cover all the cases.
Sascha, Gregory?
P.S.: "c:\new" case has been fixed. That wasn't an intention. Just a bug.
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:bksjbo$u27$1@is.intellij.net...
>
>
that
>
pretty
think
>
>
the
>
>
>
>
>
Maxim Shafirov (JetBrains) wrote:
Say I have the following code:
And I want to move the debug message into the exception message. This is
a contrived example but it's similar to something I've done before where
I was bitten by IDEA's overly smart behaviour.
If I select the text marked by [[]]:
And select the closing quote of the exception message:
and then Paste, I get the following result:
Note the erroneous escaping of the \n and an extra "\" coming from nowhere.
If however I make the first selection like so:
And make the second selection like so:
When I paste, I get the expected results:
Now you might say this is a contrived example, and I would agree with
you, but IDEA's behaviour is still wrong in the first case.
Ciao,
Gordon
--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919
I can't get into why, but those \n's cause this particular service to fail something horrible. But since I cannot rewrite that piece of code since I don't own it - I need to get Idea to not put the \n's in there if at all possible.
But as far as I understand the original thing being pasted is just wrong! It
contains newline characters where they can't be like in the middle of the
identifiers! What can I say - "garbage in - garbage out"...
Once again I can't do more that switching ALL smarts off in this case. This
way you'll get the same many lines but without leading " and trailing " +
and espaces in the middle of the query if they happen. I'm affraid this will
require much more manual editing than just removing \n's. Alternatively you
may remove newlines from the clipboard somewhere in the text editor and
repaste proper value.
Am I wrong?
--
Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
"Gregory Pierce" <no_mail@jetbrains.com> wrote in message
news:26161869.1064428573205.JavaMail.itn@is.intellij.net...
>
>
something horrible. But since I cannot rewrite that piece of code since I
don't own it - I need to get Idea to not put the \n's in there if at all
possible.
Maxim Shafirov (JetBrains) wrote:
No.
The URL with newlines is just simply NOT the URL
that should be used. Also, that wouldn't work
is pasted into M$ explorer. Are we going to ask
Mr. Gates to fix it?
Sorry, I'm fed up of this discussion.
r.
Richard Nemec wrote:
>> What can I say - "garbage in - garbage out"...
>> Am I wrong?
I believe part of the problem has to do with the fact that some other tool
auto-wraps the URL, or the copy-paste functionality does it. No sure exactly.
However, what the user seems to want is a "special" paste mode (perhaps "paste
special..."?) to strip out newlines for any string pasted in.
Maxim Shafirov (JetBrains) wrote:
I think it would be helpful would be to have two separate paste actions: one
for the Smart Paste and another for the regular Dumb Paste. Personally I
don't think I'd use the Dumb Paste very often, but this thread shows there
are definitely times when it would come in handy.
Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/
DisclaimerThis e-mail and any attachments may be confidential and/or legally
privileged. If you have received this email and you are not a named
addressee, please inform the sender at Digital Steps Ltd by phone on
+44 (0)1483 469 480 or by reply email and then delete the email from
your system. If you are not a named addressee you must not use,
disclose, distribute, copy, print or rely on this email. Although
Digital Steps Ltd routinely screens for viruses, addressees should
check this email and any attachments for viruses. Digital Steps Ltd
makes no representation or warranty as to the absence of viruses in this
email or any attachments.
I think one issue here is one of 'source'. If the CUT is from completely
within a string (things are already escaped), the paste needs to know that
so that it doesn't re-escape things that are already escaped. This could
possibly be done within IDEA, but there's nothing IDEA can do about it if
you cut from another application.
I think the only solution is to either allow an 'undo' step, as has been
indicated, or have a separate "dumb-paste" that doesn't try to escape the
string contents, so that you can invoke "dumb paste" if you KNOW the
contents of the clipboard are already properly escaped.
Personally, I think the undo-thing is probably more intuitive and easy to
do.
"Maxim Shafirov (JetBrains)" <max@intellij.net> wrote in message
news:bkspc7$evc$1@is.intellij.net...
It
>
This
will
you
>
>
>
>
>
fail
>
>
Or you could just leave the pasted string alone :) Give me the option to turn the feature off altogether so I won't get newlines all over the place where clearly they simply cannot exist :)
The original string starts off as one REALLY long line. IntelliJ breaks it up in this manner.
I think it would be cool for IDEA to have an option to show strings in code in their completely raw form, with some sort of special syntax coloring to indicate that it's the raw form. For example, if I have the string:
IDEA could show it as:
The way I'm imagining the UI is that it would resemble code folding - you could switch between the Java code view or the raw string view. Also, multi-line strings could be shown as actual multi-line strings, in a box whose upper-left corner is where the string begins in the code.
Or, alternatively, maybe someone could write a string editor plugin.
If anyone else thinks this would be cool maybe I'll file an SCR. :)
Not all the strings pasted in IDEA are meant to be printed out. Take, for
example, the SQL statements one might have in the java classes.
We often split them on multiple lines for readability. One common use case
is copying them back and forth between the java class and a SQL tool (or
the SQL plugin, for that matter) for testing purposes.
I agree with this topic's request, IDEA should allow a paste operation
that does the concatenation part, but does not include the escaping of new
lines.
Pasting the following
SELECT x1, x2, x3
FROM someTable
WHERE someConditionsHere
in a string
String s = "|";
should result in
String s = "SELECT x1, x2, x3 " +
"FROM someTable " +
"WHERE someConditionsHere";
So this version would just insert a space instead on \n. Make it an option
(I see myself using the space version most of the time) or a different
type of paste, but do provide it, please. The current behaviour it's just
too intrusive, IMO.
Thx,
Andrei
P.S.
]]>
A while ago, I filled in a feature request that was
talking about the ability to copy the concatenated string without the
concatenations(http://www.intellij.net/tracker/idea/viewSCR?publicId=12099),
but since that one was (partially) taken care of by the SQL plugin, there was no need
to pursue it further. I don't say I wouldn't like to see IDEA taking care
of this copy type as well, since the SQL plugin is not the only place the
copied string can be pasted to. :)
</slightly_offtopic>
I like your idea, but I think perhaps it'd be better implemented by removing the quotes and changing the background color of the literal string.
Please submit an SCR!
Maxim Shafirov (JetBrains wrote:
Yep, right.
>
>
>
>
>
>
>
>
>
Oops, hit the wrong key and prematurely sent the message. Sorry.
Maxim Shafirov (JetBrains) wrote:
Yep, right. I think I thought of this as part of step 2 :)
Oh, no. On the contrary. This is exactly right and this is why I distinguished
escaping and converting newlines: The escaping will be redundant (wrong)
when dealing with strings from other languages that use C-like string-escaping,
while the conversion of newlines is - as far as I can see - always right.
This might be in conflict with Gregory's problem though, which I also can't see a
good solution for: If you copy multiple lines you should get a String that contains
'\n's when pasting.
I agree that cases were IDEA seems to be oversmart are very rare but sometimes
I copy strings from other applications (Visual Studio, UltraEdit) that are already
escaped. It is very annoying to have no other way than to manually remove the
extraneous '\'s and it is kinda error prone.
I very much favor the extra undo step over a second 'dumb' paste key because
there is no new key-combination to learn. The undo is IMHO much more intuitive.
Sascha
"Vilya Harvey" <vilya.harvey@digitalsteps.com> wrote in message
news:bksvcs$ktr$1@is.intellij.net...
>
one
MSWord has several paste modes, like normal (with formatting and stuff),
unformatted, rtf, ... I hate its normal paste, I almost always use
informatted. It is not displayed in the main menu, and formatted paste is
still a default, but whatever...
Unformatted paste rules.
Is there any update on this? I'm all for having a smart paste feature, but not at the lack of my regular paste that I am used to. I find I have to undo manually what smart paste does most of the time - not necessarily because what smart paste does is incorrect but I don't need or want to see escape characters when they are not needed.
Yes, cutting and pasting SQL Queries is where this has bitten me, while I can see the logic behind the \n's it would be really nice to have an undo that got rid of them.
Damian