Closed Bug 807326 Opened 12 years ago Closed 12 years ago

Context menu Search should be available in textareas/inputs as well (Port Bug 565717)

Categories

(SeaMonkey :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
seamonkey2.19

People

(Reporter: danielbarclay.oss, Assigned: ewong)

References

Details

Attachments

(1 file, 6 obsolete files)

The function of initiating a Google (etc.) search on the text that is currently selected in a web page is not available for text in text boxes (one-line boxes and textareas). (That is, the context menu for a text selection in a text box does not have the "Search ..." menu item that a text selection in "regular" text would have.) There doesn't seem to be any reason that text in a text box shouldn't have this functionality the same way that regular text does.
From Bug 565717 Comment 0: > (Note: this is filed as part of the “Paper Cut” bugs — we assume that there may be > multiple existing bugs on this. Please make them block this bug, and we will de-dupe > if they are indeed exactly the same. Thanks!) > To reproduce: > 1. open a page with a form > 2. select some text on the page that isn't in a text input > 3. notice the "Search Google for" > 4. select some text within a text input > 5. notice the "Search Google for" is missing > Recommendation: > Add the "Search Google for" context menu when selecting text within a text input and > text area.
Severity: normal → enhancement
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Windows 7 → All
Hardware: x86_64 → All
See Also: → 565717
Summary: context-menu Search not available in text fields → Context menu Search should be available in textareas/inputsas well (Port Bug 565717)
Summary: Context menu Search should be available in textareas/inputsas well (Port Bug 565717) → Context menu Search should be available in textareas/inputs as well (Port Bug 565717)
Assignee: nobody → ewong
Status: NEW → ASSIGNED
Attachment #686020 - Flags: review?(neil)
Version: SeaMonkey 2.11 Branch → Trunk
Comment on attachment 686020 [details] [diff] [review] proposed patch to enable search for inputs. (v1) > this.initMiscItems(); >+ this.initSearchItems(); Can't you tweak initMiscItems to show the existing search option? > searchSelected: function(aCharlen) { > var focusedWindow = document.commandDispatcher.focusedWindow; > var searchStr = focusedWindow.getSelection(); > searchStr = searchStr.toString(); >+ >+ if (!searchStr) { >+ var focusedElement = document.commandDispatcher.focusedElement; Please use this.target instead. >+ if (fElem.selectionStart < fElem.selectionEnd) selectionStart is never greater than selectionEnd, although as it happens substring will swap them anyway, so no need to check. [I wonder whether it's worth checking for a text input first.]
Attachment #686020 - Flags: review?(neil) → review-
Attached patch Proposed patch (v2) (obsolete) — Splinter Review
Attachment #686020 - Attachment is obsolete: true
Attachment #697354 - Flags: review?(neil)
> + <menuseparator id="search-separator"/> > + <menuitem id="search-for-text" > + oncommand="BrowserSearch.loadSearch(gContextMenu.searchSelected(), true, event);"/> I think you need to update the tests as well: suite/browser/test/mochitest/test_contextmenu.html suite/browser/test/mochitest/subtst_contextmenu.html
Fixed tests.
Attachment #697354 - Attachment is obsolete: true
Attachment #697354 - Flags: review?(neil)
Attachment #698206 - Flags: review?(neil)
Attachment #698206 - Attachment is patch: true
Comment on attachment 698206 [details] [diff] [review] Context menu search should be available in textareas/inputs as well (Port Bug 565717) (v3) > var menuLabel = bundle.getFormattedString("contextMenuSearchText", > [engineName, searchSelectText]); >+ var menuLabelSearch = bundle.getFormattedString("searchForText", >+ [engineName, searchSelectText]); >+ > this.setItemAttr("context-searchselect", "label", menuLabel); > this.setItemAttr("context-searchselect", "accesskey", > bundle.getString("contextMenuSearchText.accesskey")); > >+ this.setItemAttr("search-for-text", "label", menuLabelSearch); >+ this.setItemAttr("search-for-text", "accesskey", >+ bundle.getString("searchForText.accesskey")); You're just duplicating effort here, you should just tweak the code that shows the existing context search item to show when you have a selection in a text field as well. >+ if (!searchStr) { >+ var focusedElement = this.target; >+ if ((focusedElement instanceof HTMLInputElement && >+ focusedElement.mozIsTextField(true)) || >+ focusedElement instanceof HTMLTextAreaElement) { >+ var fElem = focusedElement; >+ searchStr = fElem.value.substring(fElem.selectionStart, fElem.selectionEnd); Unnecessary variable(s). "this.target" is actually less typing than "focusedElement"! We have a problem because we now get the context menu for disabled form controls. One approach is to use if (this.onTextInput) instead if if (!searchStr).
Attachment #698206 - Flags: review?(neil) → review-
same as v4 but needed to change the key=value pair for contextMenuSearchText as the accesskey was changed.
Attachment #700829 - Attachment is obsolete: true
Attachment #700829 - Flags: review?(neil)
Attachment #700830 - Flags: review?(neil)
Comment on attachment 700830 [details] [diff] [review] Context menu search should be available in textareas/inputs as well (Port Bug 565717) (v5) We're getting close! >+ this.showItem("context-searchselect", this.onTextInput && this.isTextSelected); There's already a this.showItem for context-searchselect, you need to tweak the existing one instead of adding a new one. Otherwise search selected stops working for normal selection ;-) >+ if (this.onTextInput) { >+ if ((this.target instanceof HTMLInputElement && >+ this.target.mozIsTextField(true)) || >+ this.target instanceof HTMLTextAreaElement) { >+ var fElem = this.target; >+ searchStr = fElem.value.substring(fElem.selectionStart, fElem.selectionEnd); If you want to keep fElem, then move it up three lines so that you can switch from this.target to fElem in more places. > # LOCALIZATION NOTE (contextMenuSearchText): %1$S is the search engine, > # %2$S is the selection string. >-contextMenuSearchText=Search %1$S for "%2$S" >-contextMenuSearchText.accesskey=S >+contextMenuSearchTextValue=Search %1$S for "%2$S" >+contextMenuSearchTextValue.accesskey=e You forgot to rename the l10n note. Also, that's a lame string name, any chance you could simplify it to searchSelected[.accesskey]?
Attachment #700830 - Attachment is obsolete: true
Attachment #700830 - Flags: review?(neil)
Attachment #715850 - Flags: review?(neil)
Comment on attachment 715850 [details] [diff] [review] Context menu search should be available in textareas/inputs as well (Port Bug 565717) (v6) This is functionally correct, but please fix these before check in! >+ this.showItem("context-searchselect", >+ (this.isTextSelected && !this.onTextInput) || >+ (this.onTextInput && this.isTextSelected)); This expression is unnecessarily complex. > (this.isTextSelected && !this.onTextInput) || > (this.onTextInput && this.isTextSelected) commutativity of && is allowed in this case: > (this.isTextSelected && !this.onTextInput) || > (this.isTextSelected && this.onTextInput) && distributes over ||: > this.isTextSelected && (!this.onTextInput || this.onTextInput) Hopefully you can figure the rest out. >+ var fElem = this.target; >+ if (this.onTextInput) { Nit: put fElem inside this if because you only use it there. > # LOCALIZATION NOTE (contextMenuSearchText): %1$S is the search engine, > # %2$S is the selection string. >-contextMenuSearchText=Search %1$S for "%2$S" >-contextMenuSearchText.accesskey=S >+searchSelected=Search %1$S for "%2$S" >+searchSelected.accesskey=e Nit: need to fix the L10N note.
Attachment #715850 - Flags: review?(neil) → review+
Attachment #719790 - Flags: review?(neil) → review+
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → seamonkey2.19
Depends on: 856587
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: