r96415 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96414‎ | r96415 | r96416 >
Date:11:39, 7 September 2011
Author:junaidpv
Status:ok (Comments)
Tags:
Comment:
Applying workaround locally within the extension Narayam for webkit browsers as reported in bug 30130. Should be removed this fix when it is handled within jQuery.textSelection.js. It will be very slow in fact when editting very long text within webkit browsers, better to edit by section.
Modified paths:
  • /trunk/extensions/Narayam/js/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/js/ext.narayam.core.js
@@ -150,6 +150,27 @@
151151 }
152152
153153 /**
 154+ * Replace text part from startPos to endPos with peri
 155+ * It function is specifically for webkit browsers,
 156+ * because of bug: https://bugs.webkit.org/show_bug.cgi?id=66630
 157+ * TODO: remove when webkit bug is handled in jQuery.textSelection.js
 158+ *
 159+ * @param $element jQuery object to wich replacement to be taked place
 160+ * @param startPos Starting position of text range to be replaced
 161+ * @param endPos Ending position of text range to be replaced
 162+ * @param peri String to be substituted
 163+ */
 164+ function replaceString( $element, startPos, endPos, peri ) {
 165+ // Take entire text of the element
 166+ var text = $element.val();
 167+ var pre = text.substring( 0, startPos );
 168+ var post = text.substring( endPos, text.length );
 169+
 170+ // Then replace
 171+ $element.val( pre + peri + post );
 172+ }
 173+
 174+ /**
154175 * Keydown event handler. Handles shortcut key presses
155176 * @param e Event object
156177 */
@@ -221,16 +242,35 @@
222243 input = input.substring( divergingPos );
223244 replacement = replacement.substring( divergingPos );
224245
225 - // Select and replace the text
226 - $this.textSelection( 'setSelection', {
227 - 'start': startPos - input.length + 1,
228 - 'end': endPos
229 - } );
230 - $this.textSelection( 'encapsulateSelection', {
231 - 'peri': replacement,
232 - 'replace': true,
233 - 'selectPeri': false
234 - } );
 246+ // TODO: use better browser detection as $.browser may be moved out
 247+ // from jQuery core
 248+ if ( $.browser.webkit ) {
 249+ // Webkit browser have a bug:
 250+ // https://bugs.webkit.org/show_bug.cgi?id=66630
 251+ // TODO: remove when webkit bug is handled
 252+ // in jQuery.textSelection.js
 253+
 254+ replaceString($this, startPos - input.length + 1, endPos, replacement);
 255+ // Calculate new position for caret to be set
 256+ var newCaretPosition = startPos - input.length + 1 + replacement.length
 257+ // Update caret postion
 258+ $this.textSelection( 'setSelection', {
 259+ 'start': newCaretPosition,
 260+ 'end': newCaretPosition
 261+ } );
 262+ }
 263+ else {
 264+ // Select and replace the text
 265+ $this.textSelection( 'setSelection', {
 266+ 'start': startPos - input.length + 1,
 267+ 'end': endPos
 268+ } );
 269+ $this.textSelection( 'encapsulateSelection', {
 270+ 'peri': replacement,
 271+ 'replace': true,
 272+ 'selectPeri': false
 273+ } );
 274+ }
235275
236276 e.stopPropagation();
237277 return false;

Follow-up revisions

RevisionCommit summaryAuthorDate
r96579(bug 30130) Add selectionStart and selectionEnd parameters to encapsulateSele...catrope16:05, 8 September 2011
r97466Remove webkit specific slow code with generic approach with the help of jquer...santhosh11:07, 19 September 2011

Comments

#Comment by Siebrand (talk | contribs)   11:40, 7 September 2011

Great work. Thanks.

Status & tagging log