Mercurial > hip
changeset 11:9e18b8d8c936
Added simple text-selection support; use words like 'this', 'selection', or 'it' to refer to your selection. It will be interpolated in the correct position in your sentence. I don't have a selection-grabbing mechanism yet (it's beside the point) so I just added a text input field to hip.html that we will pretend is your selection for not.
author | jonathandicarlo@localhost |
---|---|
date | Fri, 16 May 2008 19:43:45 -0700 |
parents | 8f6b1c89d8de |
children | aa56c4aa5b11 |
files | hip.html hip.js |
diffstat | 2 files changed, 47 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/hip.html Wed May 14 22:08:44 2008 -0700 +++ b/hip.html Fri May 16 19:43:45 2008 -0700 @@ -11,6 +11,8 @@ <div id="status-line">Ubiquity!</div> <input id="search-box" type="text" size="40" /> <div id="autocomplete-popup"></div> + <hr/> + <p>Pretend this is your selection: <input id="selection" type="text" size=30" /></p> </body> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="hip.js"></script>
--- a/hip.js Wed May 14 22:08:44 2008 -0700 +++ b/hip.js Fri May 16 19:43:45 2008 -0700 @@ -10,6 +10,12 @@ return [ key for ( key in dict ) ]; } +function getSelection () { + return $("#selection").attr( "value" ); +} + +var wordsThatReferToSelection = [ "this", "that", "it", "selection", "him", "her", "them"]; // not currently used (there's a hard-coded "this") but it easily could be + function NounType( name, expectedWords ) { this._init( name, expectedWords ); } @@ -244,7 +250,31 @@ 2. a preposition 3. a noun following a preposition. */ - return this.recursiveParse( words, {}, this._modifiers ); + + /* Look for words that refer to selection: */ + var completions = []; + var subbedWords = words.slice(); + var selectionUsed = false; + var selection = getSelection(); + if ( selection ) { + for ( var x in wordsThatReferToSelection ) { + var index = subbedWords.indexOf( wordsThatReferToSelection[x] ); + if ( index > -1 ) { + subbedWords.splice( index, 1, selection ); + // Notice the above line doesn't do what I want if selection + // is more than one word. + selectionUsed = true; + } + } + } + if ( selectionUsed ) { + completions = this.recursiveParse( subbedWords, {}, this._modifiers ); + } + + /* Also parse without that substitution, return both ways: */ + var completionsNoSub = this.recursiveParse( words, {}, this._modifiers ); + completions = completions.concat( completionsNoSub ); + return completions; }, match: function( sentence ) { @@ -381,18 +411,6 @@ var verbs = [ fly, define, google, go, close, open, translate, email, nuke, encrypt, wiki ]; -/* Initial state: no verb determined. - After each keypress, update verb suggestion list. - After first spacebar: lock in top verb from suggestion list. Create - parsedSentence object based on verb. change state to sentence completion. - Non-keystroke spaces after that: - spacebar sends the lock-in-last-word message to lockedInSentence. - - todo: add responder for arrow keys to hilight suggestions - and escape to clear text. -*/ - - function QuerySource() { this._init( ); } @@ -511,6 +529,7 @@ // down arrow is 40 // enter is 13 // space is 32 + var input = event.target.value; switch( event.which ) { case 27: //esc event.target.value = ""; @@ -526,11 +545,11 @@ gQs.execute(); break; case 32: // spacebar - event.target.value = gQs.autocomplete( event.target.value ); - gQs.updateSuggestionList( event.target.value ); + input = gQs.autocomplete( input ); + gQs.updateSuggestionList( input ); break; default: - gQs.updateSuggestionList( event.target.value ); + gQs.updateSuggestionList( input ); break; } @@ -557,10 +576,6 @@ fly from london nuke london -2. If you have a selection, put the magic word "this" ( or "selection" ) into your sentence to indicate where you want the selection to go, e.g. -email this to aza (with content selected) -vs -email hello there to this (with an email address selected) 3. Allow the possibility of a multiple-word indirect-object @@ -574,4 +589,14 @@ 6. More complex datatypes, like dates, that allow for multiple input formats. ( see http://www.datejs.com/ ) +7. Make verbs more tolerant of text that doesn't match the direct object. +First of all, if the direct object text is just spaces (and how does that +happen?) it should be discarded. And then, if there's input that can't +be used, maybe discard it or put it in red or something, rather than +rejecting it. + +8. Tweak what text gets autocompleted when you arrow down to something +and hit space. Right now it's putting in prepositions that you haven't +actually typed. + */