-
Notifications
You must be signed in to change notification settings - Fork 49
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
Support pasting layout XML from outside of IntelliJ / Android Studio #8 #81
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Just a couple of questions and then I think this can land. :)
return emptyList() | ||
return if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) { | ||
val text = content.getTransferData(DataFlavor.stringFlavor) as String | ||
val xmlPreamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) | ||
} | ||
text.contains(xmlPreamble, true) -> { | ||
listOf(CopiedXMLCode(text, intArrayOf(0), intArrayOf(0)) as TextBlockTransferableData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we set the endOffset
to the last index of text
? Right now the offsets are not used, but eventually they will, I guess (#5).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, i wasn't sure what the correct values for the offsets are. I looked at what offsets are used in collectTransferableData() when i copy the text inside Intellij and they we both 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Then this is something to look at when tackling #5. I was expecting the offsets to mark the selection area inside the text, since right now that always contains the whole document. But if it's always 0 right now then let's just use 0 here for now too. 👍
val xmlPreamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | ||
|
||
when { | ||
content.isDataFlavorSupported(CopiedXMLCode.DATA_FLAVOR) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever get here if this block is wrapped in DataFlavor.stringFlavor
? Is that an extension of the string flavor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can only get here when the content has one flavour with DataFlavor.stringFlavor, see row 63.
I'm first checking if the pasted content is a string and not e.g. an image file. Then i'm checking if the content also has the dataflavor of CopiedXMLCode. If it's not, i'm checking if it looks like XML.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright 👍
Hi, maybe there's a better way to check if a string is XML but i found a similar approach in the Kotlin Project