code review 6847118: goplay: does not work on IE. (issue 6847118)

100 views
Skip to first unread message

matt...@gmail.com

unread,
Nov 28, 2012, 2:32:20 AM11/28/12
to golan...@googlecode.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: golang-dev_googlecode.com,

Message:
Hello golan...@googlecode.com (cc: golan...@googlegroups.com),

I'd like you to review this change to
http://go.googlecode.com/hg/


Description:
goplay: does not work on IE.

Please review this at http://codereview.appspot.com/6847118/

Affected files:
M misc/goplay/goplay.go


Index: misc/goplay/goplay.go
===================================================================
--- a/misc/goplay/goplay.go
+++ b/misc/goplay/goplay.go
@@ -177,24 +177,61 @@
function insertTabs(n) {
// find the selection start and end
var cont = document.getElementById("edit");
- var start = cont.selectionStart;
- var end = cont.selectionEnd;
- // split the textarea content into two, and insert n tabs
- var v = cont.value;
- var u = v.substr(0, start);
- for (var i=0; i<n; i++) {
- u += "\t";
+ if (cont.selectionStart) {
+ var start = cont.selectionStart;
+ var end = cont.selectionEnd;
+ // split the textarea content into two, and insert n tabs
+ var v = cont.value;
+ var u = v.substr(0, start);
+ for (var i=0; i<n; i++) {
+ u += "\t";
+ }
+ u += v.substr(end);
+ // set revised content
+ cont.value = u;
+ // reset caret position after inserted tabs
+ cont.selectionStart = start+n;
+ cont.selectionEnd = start+n;
+ } else {
+ var v = cont.value;
+ var start = getCaretPosition(cont);
+ var u = v.substr(0, start);
+ for (var i=0; i<n; i++) {
+ u += "\t";
+ }
+ u += v.substr(start);
+ cont.value = u;
+ range = cont.createTextRange();
+ range.collapse(true);
+ range.moveStart('character', v.substr(0,
start).replace(/\r/g, '').length+n);
+ range.moveEnd('character', 0);
+ range.select();
}
- u += v.substr(end);
- // set revised content
- cont.value = u;
- // reset caret position after inserted tabs
- cont.selectionStart = start+n;
- cont.selectionEnd = start+n;
+
+}
+
+function getCaretPosition(el) {
+ if (el.selectionStart)
+ return el.selectionStart;
+ var range = document.selection.createRange();
+ var len = el.value.length;
+ var text = el.value.replace(/\r\n/g, "\n");
+
+ var spos = el.createTextRange();
+ spos.moveToBookmark(range.getBookmark());
+ var epos = el.createTextRange();
+ epos.collapse(false);
+
+ if (spos.compareEndPoints("StartToEnd", epos) > -1) {
+ return len;
+ }
+ var start = -spos.moveStart("character", -len);
+ start += text.slice(0, start).split("\n").length - 1;
+ return start;
}

function autoindent(el) {
- var curpos = el.selectionStart;
+ var curpos = getCaretPosition(el);
var tabs = 0;
while (curpos > 0) {
curpos--;
@@ -213,6 +250,7 @@
if (e.preventDefault) {
e.preventDefault();
} else {
+ e.returnValue = false;
e.cancelBubble = true;
}
}
@@ -226,11 +264,11 @@
}
if (e.keyCode == 13) { // enter
if (e.shiftKey) { // +shift
- compile(e.target);
+ compile(e.target || e.srcElement);
preventDefault(e);
return false;
} else {
- autoindent(e.target);
+ autoindent(e.target || e.srcElement);
}
}
return true;


0xj...@gmail.com

unread,
Nov 28, 2012, 3:45:41 AM11/28/12
to matt...@gmail.com, golan...@googlecode.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
On 2012/11/28 07:32:20, mattn wrote:
> I'd like you to review this change to
> http://go.googlecode.com/hg/

- Which/what issue does this fix?

- Is the current code not following the standards or is IE not following
the standards? In the later case I don't like the idea of IE specific
hacks.



https://codereview.appspot.com/6847118/

matt...@gmail.com

unread,
Nov 28, 2012, 4:01:18 AM11/28/12
to golan...@googlecode.com, 0xj...@gmail.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
> - Which/what issue does this fix?

Current code contains some part for IE by halves (See preventDefault).
Probably, I added this part in long ago. However i didn't check goplay
working for a while.

> - Is the current code not following the standards or is IE not
following the standards? In the later case I don't like the idea of IE
specific hacks.

IE does not support HTML5, so selection APIs is not exists.

http://www.w3.org/TR/html5/editing.html#selection-0

I don't know whether dev-team support IE for a long time(?) or not.

https://codereview.appspot.com/6847118/

minux

unread,
Nov 28, 2012, 6:15:10 AM11/28/12
to matt...@gmail.com, golan...@googlecode.com, 0xj...@gmail.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
personally, i do not care much about ie support given that
we have many much better free alternatives.

in fact, iirc, even golang.org doesn't look right under ie.

Russ Cox

unread,
Nov 28, 2012, 9:05:10 AM11/28/12
to minux, matt...@gmail.com, golan...@googlecode.com, 0xj...@gmail.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Which version of IE is this fixing? It would be nice to support at
least the most recent one, assuming it is not too difficult. But I am
not worried about 5-year-old IEs.

Russ

Yasuhiro MATSUMOTO

unread,
Nov 28, 2012, 9:44:40 AM11/28/12
to Russ Cox, minux, golan...@googlecode.com, 0xj...@gmail.com, golan...@googlegroups.com, re...@codereview-hr.appspotmail.com
Sorry for top post, I'm writing from mobile handy phone.

minux:
I'm thinking it's not difficult to support IE, golang.org does not
contains many HTML5 stuff or modern browser specific codes as worry
about.

russ:
I checked on IE8.
--
- Yasuhiro Matsumoto
Reply all
Reply to author
Forward
0 new messages