⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 237482 in webkit


Ignore:
Timestamp:
Oct 26, 2018, 2:03:47 PM (8 years ago)
Author:
Devin Rousso
Message:

Web Inspector: simplify some editing code checks
​https://bugs.webkit.org/show_bug.cgi?id=190970

Reviewed by Joseph Pecoraro.

  • UserInterface/Base/Main.js:

(WI._focusChanged):

  • UserInterface/Base/Utilities.js:
  • UserInterface/Views/EditingSupport.js:

(WI.enclosingCodeMirror): Added.
(WI.isBeingEdited):
(WI.isEventTargetAnEditableField):

  • UserInterface/Views/QuickConsole.js:

(WI.QuickConsole):

Location:
trunk/Source/WebInspectorUI
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r237481 r237482  
     12018-10-26  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: simplify some editing code checks
     4        https://bugs.webkit.org/show_bug.cgi?id=190970
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * UserInterface/Base/Main.js:
     9        (WI._focusChanged):
     10
     11        * UserInterface/Base/Utilities.js:
     12
     13        * UserInterface/Views/EditingSupport.js:
     14        (WI.enclosingCodeMirror): Added.
     15        (WI.isBeingEdited):
     16        (WI.isEventTargetAnEditableField):
     17
     18        * UserInterface/Views/QuickConsole.js:
     19        (WI.QuickConsole):
     20
    1212018-10-26  Devin Rousso  <drousso@apple.com>
    222
  • trunk/Source/WebInspectorUI/UserInterface/Base/Main.js

    r237212 r237482  
    12951295    if (WI.isEventTargetAnEditableField(event)) {
    12961296        // Still update the currentFocusElement if inside of a CodeMirror editor or an input element.
    1297         let codeMirrorEditorElement = event.target.enclosingNodeOrSelfWithClass("CodeMirror");
    1298         if (codeMirrorEditorElement && codeMirrorEditorElement !== this.currentFocusElement) {
     1297        let newFocusElement = null;
     1298        if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement)
     1299            newFocusElement = event.target;
     1300        else {
     1301            let codeMirror = WI.enclosingCodeMirror(event.target);
     1302            if (codeMirror) {
     1303                let codeMirrorElement = codeMirror.getWrapperElement();
     1304                if (codeMirrorElement && codeMirrorElement !== this.currentFocusElement)
     1305                    newFocusElement = codeMirrorElement;
     1306            }
     1307        }
     1308
     1309        if (newFocusElement) {
    12991310            this.previousFocusElement = this.currentFocusElement;
    1300             this.currentFocusElement = codeMirrorEditorElement;
    1301         } else if (event.target.tagName === "INPUT") {
    1302             this.previousFocusElement = this.currentFocusElement;
    1303             this.currentFocusElement = event.target;
     1311            this.currentFocusElement = newFocusElement;
    13041312        }
    13051313
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r237436 r237482  
    380380});
    381381
    382 Object.defineProperty(Element.prototype, "removeMatchingStyleClasses",
    383 {
    384     value(classNameRegex)
    385     {
    386         var regex = new RegExp("(^|\\s+)" + classNameRegex + "($|\\s+)");
    387         if (regex.test(this.className))
    388             this.className = this.className.replace(regex, " ");
    389     }
    390 });
    391 
    392382Object.defineProperty(Element.prototype, "createChild",
    393383{
  • trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js

    r230001 r237482  
    2424 */
    2525
     26WI.enclosingCodeMirror = function(element)
     27{
     28    while (element) {
     29        if (element.CodeMirror)
     30            return element.CodeMirror;
     31        element = element.parentNode;
     32    }
     33    return null;
     34};
     35
    2636WI.isBeingEdited = function(element)
    2737{
    … …  
    3141        element = element.parentNode;
    3242    }
    33 
    3443    return false;
    3544};
    … …  
    5867WI.isEventTargetAnEditableField = function(event)
    5968{
    60     let textInputTypes = new Set(["text", "search", "number", "tel", "url", "email", "password"]);
    61     if (event.target instanceof HTMLInputElement)
    62         return textInputTypes.has(event.target.type);
    63 
    64     let codeMirrorEditorElement = event.target.enclosingNodeOrSelfWithClass("CodeMirror");
    65     if (codeMirrorEditorElement && codeMirrorEditorElement.CodeMirror)
    66         return !codeMirrorEditorElement.CodeMirror.getOption("readOnly");
    67 
    68     if (event.target instanceof HTMLTextAreaElement)
     69    if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement)
    6970        return true;
    7071
    … …  
    7273        return true;
    7374
    74     if (event.target.enclosingNodeOrSelfWithClass("text-prompt"))
    75         return true;
    76 
    7775    if (WI.isBeingEdited(event.target))
    7876        return true;
     77
     78    let codeMirror = WI.enclosingCodeMirror(event.target);
     79    if (codeMirror)
     80        return !codeMirror.getOption("readOnly");
    7981
    8082    return false;
  • trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js

    r236885 r237482  
    4545
    4646        this.prompt = new WI.ConsolePrompt(null, "text/javascript");
    47         this.prompt.element.classList.add("text-prompt");
    4847        this.addSubview(this.prompt);
    4948
Note: See TracChangeset for help on using the changeset viewer.