diff --git a/@client/edit_point.coffee b/@client/edit_point.coffee index 7d30703dd..a4018dbae 100644 --- a/@client/edit_point.coffee +++ b/@client/edit_point.coffee @@ -56,6 +56,9 @@ window.EditPoint = ReactiveComponent position: 'absolute' right: 0 top: -21 + onInput: (event) => + if event and event.target + setStateNewPointInput(extractWords(event.target.value)) INPUT id:'is_pro' @@ -242,6 +245,8 @@ window.EditPoint = ReactiveComponent your_points.editing_points = _.without your_points.editing_points, @props.point save your_points + clearStateNewPointInput() + savePoint : (ev) -> diff --git a/@client/point.coffee b/@client/point.coffee index 4f69e7ea7..e74e7935b 100644 --- a/@client/point.coffee +++ b/@client/point.coffee @@ -20,6 +20,7 @@ window.Point = ReactiveComponent current_user = fetch('/current_user') + new_point_words = getStateNewPointInput() renderIncluders = (draw_all_includers) => @@ -178,7 +179,7 @@ window.Point = ReactiveComponent DIV className: 'point_nutshell' - splitParagraphs point.nutshell, append + splitParagraphs point.nutshell, append, new_point_words diff --git a/@client/pro_con_widget.coffee b/@client/pro_con_widget.coffee index 1713055d7..d4519ec89 100644 --- a/@client/pro_con_widget.coffee +++ b/@client/pro_con_widget.coffee @@ -20,6 +20,18 @@ window.getProposalMode = (proposal) -> local_state.mode +window.clearStateNewPointInput = -> setStateNewPointInput(null) + +window.setStateNewPointInput = ( new_point_input ) -> + state_of_new_point_input = fetch('new_point_input') + state_of_new_point_input['words'] = new_point_input + save state_of_new_point_input + +window.getStateNewPointInput = ( new_point_input ) -> + state_of_new_point_input = fetch('new_point_input') + return if state_of_new_point_input then state_of_new_point_input['words'] else null + + window.update_proposal_mode = (proposal, proposal_mode, triggered_by) -> can_opine = canUserOpine proposal proposal = fetch proposal @@ -31,6 +43,8 @@ window.update_proposal_mode = (proposal, proposal_mode, triggered_by) -> (can_opine == Permission.DISABLED && your_opinion.key)) proposal_mode = 'results' + else + clearStateNewPointInput() local_state = fetch shared_local_key proposal if local_state.mode != proposal_mode @@ -1501,4 +1515,4 @@ GroupSelectionRegion = ReactiveComponent color: focus_color() left: "min(#{wrapper_width - name_width}px, max(0px, calc(#{left}px - #{name_width / 2}px)))" #Math.min(wrapper_width - name_width - 10, Math.max(0, left - name_width / 2)) title - \ No newline at end of file + diff --git a/@client/shared.coffee b/@client/shared.coffee index 12e60b47e..716f34958 100644 --- a/@client/shared.coffee +++ b/@client/shared.coffee @@ -506,9 +506,40 @@ safe_string = (user_content) -> user_content -window.splitParagraphs = (user_content, append) -> + +window.STOP_WORDS = new Set( [ + "a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "aren't", + "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", + "can't", "cannot", "could", "couldn't", "did", "didn't", "do", "does", "doesn't", "doing", "don't", + "down", "during", "each", "few", "for", "from", "further", "had", "hadn't", "has", "hasn't", "have", + "haven't", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", + "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "isn't", + "it", "it's", "its", "itself", "let's", "me", "more", "most", "mustn't", "my", "myself", "nor", "not", + "of", "off", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", + "own", "same", "shan't", "she", "she'd", "she'll", "she's", "should", "shouldn't", "so", "some", "such", + "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", + "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", + "under", "until", "up", "very", "was", "wasn't", "we", "we'd", "we'll", "we're", "we've", "were", + "weren't", "what", "what's", "when", "when's", "where", "where's", "which", "while", "who", "who's", + "whom", "why", "why's", "with", "won't", "would", "wouldn't", "you", "you'd", "you'll", "you're", + "you've", "your", "yours", "yourself", "yourselves" ] ) + +window.extractWords = ( text ) -> + # Split discarding non-alpha-numeric delimiters, lowercase, filter stop-words + words = if text then text.toLowerCase().split( /\W+/ ) else [] + return words.filter( (w) -> !STOP_WORDS.has(w) and (1 < w.length) ) + +window.extractTokens = ( text ) -> + # Split keeping delimiters, punctuation, original case + tokens = if text then text.split( /(\W+)/ ) else [] + return tokens + + +window.splitParagraphs = (user_content, append, highlightWords) -> if !user_content return SPAN null + + highlightWords = highlightWords or null user_content = safe_string user_content @@ -527,6 +558,15 @@ window.splitParagraphs = (user_content, append) -> if text.substring(0,5) == 'link:' A key: idx, href: text.substring(5, text.length), target: '_blank', text.substring(5, text.length) + else if highlightWords + SPAN + key: idx + for token,tokenIndex in extractTokens(text) + SPAN + key:tokenIndex + style: + backgroundColor: if highlightWords.includes(token.toLowerCase()) then 'yellow' else null + token else SPAN key: idx, text