This question is fairly fundamental but I can't find a solution anywhere. There are many examples of highlighting text in javascript with or without jQuery, but I'm having trouble figuring it out in Dart.
The Selection and Range classes appear to support this but the documentation is kind of sparse.
Okay while trying to write the question thoroughly I figured it out. It's actually quite simple.
HTML: <p id='text'></p>
Dart:
var text = querySelector('#text');
Using Selection only:
window.getSelection().selectAllChildren(text);
Using Range and Selection:
var range = document.createRange();
range.selectNodeContents(text);
window.getSelection().addRange(range);
Both examples select all of the text inside the node. For more information on how to use Range, see this answer.
Related
I am trying go find an option that does this kind of highlighting that is quick/easy to use within a Jira ticket. The links below I have read through. I don't want to use a {code} bracket every time I want to highlight a keyword or attribute to pay attention to ie:
schema.tableName.myColumn = true.
You can easily do this within Microsoft Teams, Discord if you are having trouble understanding what I am looking for. Is there anything else that is in the works or currently out there for the Jira community to use? Something as easy as using tick marks?
Resources Viewed:
Using a {code} block
Highlighting words with <style>
Code Block Macro
Closest to this, out of the box is the {{monospaced}} formatting. Just enclose the text with double curly quotes {{,}}. No fancy syntax highlighting though. See Jira's Wiki Style Renderer guide.
If you like, you could also try this plugin Markin.
With Vaadin 8 you could set a tooltip for a Grid cell. This feature is not available in Vaadin Flow (currently using v 11.0.0). Is there an alternative?
There is no built-in feature yet. The easiest way is probably to set "title" attribute of the element. One example is to use TemplateRenderer, and there is example of that here
https://vaadin.com/components/vaadin-grid/java-examples/using-templates
Copying the relevant part of the code from the example above
grid.addColumn(TemplateRenderer.<Person> of(
"<div title='[[item.name]]'>[[item.name]]<br><small>[[item.yearsOld]]</small></div>")
.withProperty("name", Person::getName).withProperty("yearsOld",
person -> person.getAge() > 1
? person.getAge() + " years old"
: person.getAge() + " year old"))
.setHeader("Person");
Thanks to #Tatu-Lund's answer I got the idea, but since the link is not referring to a valid location anymore, and also the example code with div can bring other complexities into the game I decided to post another answer.
Using div as the wrapper element to have the title attribute would work, but it will prevent the columns to be resized. So using span would be a good replacement.
Also, setting the title would help with a normal tooltip to show up, but it is not enough for accessibility support. Setting the aria-label in addition to the title would make it smoother:
grid.addColumn(TemplateRenderer.<Person> of(
"<span title='[[item.name]]' aria-label='[[item.name]]'>[[item.name]]</span>")
.withProperty("name", Person::getName)
.setHeader("Person");
However, this is not a complete workaround as this would not help to browse the web app on touch devices. Please refer to the following issue for more information: https://github.com/vaadin/flow/issues/4169
I'm making a custom keyboard for lawyers, and trying to load law related words in suggestion/prediction bar on top the keyboard based on what user types. Just like in stock keyboard. I have searched around but did not find any concrete answer.
I want to display suggestions of law related terms that I have in a txt file, all words are sorted alphabetically.
DEMO
Here is what I have tried:
UILexicon
let myLexicon = NSMutableDictionary()
self.requestSupplementaryLexiconWithCompletion { (theLexicon: UILexicon!) -> Void in
let lexiconEntries = theLexicon.entries
// Completion handler
for item in lexiconEntries {
self.myLexicon.setObject(item.documentText, forKey: item.userInput)
}
}
This code just gives 23 nil objects.
UITextChecker This is an iOS class that is designed to spot spelling errors, which makes it perfect for knowing if a given word is real or not. This is seems to be mainly for autocorrection, not for suggestion. Correct me if I'm wrong please.
I cannot somehow make sense out of these two classes.
How do I tell custom keyboard, "Hey if user enters "V" show the top 3 words that start from V, then if user enter a, fill the suggestion bar with words that start with "Va" and so on.
EDIT: Looks like someone ran into same problem. Here is a quote how they solved it, I will update with code once I finish figuring this out myself.
However, this was far from the truth - in fact, Apple do not allow access to their dictionary full stop, only offering a UILexicon class instead as stated in their docs:
Make use of this class, along with a lexicon of your own design, to provide suggestions and autocorrections as users are entering text.
As it turns out, the UILexicon class only really contains contact names along with any shortcuts (like the default On My Way!) defined on the device. So before writing the logic for a keyboard, you first have to implement your own autocorrect library.
We browsed through a few external projects to see if we could include them in the keyboard - most notably Hunspell, which is used by OpenOffice, and Presage, an intelligent predictive text library.
I spent a long time integrating the C++ libraries with the code, but in the end, in order to keep complexity down, we opted to use a combination of UITextChecker (which provides some basic corrections) and our own custom dictionary, containing a few commonly mispelled words.
Link to the Article
Thanks!
You have to implement your own autocorrection system. UILexicon will only give you shortcuts the user has set up, words that they have added to the iOS Dictionary, and names of contacts. It has no awareness of any words that you yourself provide, whether in a txt file or in any other form.
If you want to use the TOMSSuggestionBar, it appears from the sample code that the onus is on you to convert your txt file into a core data model, and indicate to the suggestion bar how it is to interpret the contents of that model. You may also want to implement the data source protocol to get more fine grained control over the suggestions.
Autocorrection and next word prediction are not solved problems; I suggest you do your own research and find the solution that is best suited to your goals.
In a polymer element I can bind a property like this:
<input type="text" value="{{value}}">
But if I create the html element dynamically in the script:
TextInputElement newElement = new TextInputElement();
How can I achieve the binding?
You can have a look at
Creating a dataList programatically
Dart: Dynamic usage of polymer-ui-tabs and polymer-ui-pages does not work
there was a similar question for Polymer.js recently with a simpler solution (Data binding for dynamically generated HTML in Polymer?) but I haven't seen anything similar for Polymer.dart yet.
I'll try to find something tomorrow, it's rather late here already ...
I created this issue http://dartbug.com/21029
This is fixed now with injectBoundHtml.
See also https://groups.google.com/a/dartlang.org/d/msg/web/uqri0fpGH10/dPm169WUiUwJ for more details.
I use this workaround (polymer 0.15.5+4):
var template = new TemplateElement()
..setInnerHtml("<p>Reversed: {{ reversed }}</p>");
var fragment = this.instanceTemplate(template);
this.shadowRoot.append(fragment);
But it seems rather complex for me and i've not found more elegant solution for a while.
I feel confused by Günter's phrase "The used expressions must already be used somewhere so Smoke knows to generate code for them." from Dart: Dynamic usage of polymer-ui-tabs and polymer-ui-pages does not work thread. Can somebody from this thread light this moment?
The auto_complete_for dealio from script.aculo.us is great an all, but is there a way for me to selectively disable the fact that it always auto-selects the first item in the list?
The problem is that, if I want to type my own entry that is new, and novel, I don't want the first item in the list to be auto-selected. The reason is because when I TAB out of the field, it selects, and fills the text box with that first item.
I got around that, somewhat, by making the first item in the list the same as what I'm typing, but that's not perfect either, because the auto_complete list doesn't always update with every keystroke, depending on how fast I type. I've tried setting the list refresh rate to the lowest value (1 millisecond) but no go.
What I really want is an option in "auto_complete_for" that doesn't select that first item at all - the same way that Google Instant doesn't automatically select the first suggested search phrase - you have to arrow-down to select one.
Maybe I can do this via an HTML option that I'm missing?
Looking at the source, there doesn't appear to be an option for that, but I bet if you changed line 284 of controls.js to this.index = -1; it would do what you want.
Otherwise, it might be time to look for a different autocomplete widget.
If your requirements are too far away from the available plugin, then I guess there is no point in tinkering around. Its best to write your own JS code.
You might want to consider this: https://github.com/laktek/jQuery-Smart-Auto-Complete
or this : https://github.com/reinh/jquery-autocomplete
I'll add another alternative that works great with Rails 3:
http://github.com/crowdint/rails3-jquery-autocomplete
I recently implemented auto complete for more than a field for Rails 2.0.2.
The plugin I used is:- https://github.com/david-kerins/auto_complete . Not sure if it supports Rails 3.
I have also encountered issues on implementing the above scenario and have posted questions( Implementing auto complete for more than one field in Rails ; Implementing a OnClick kind of functionality and formatting wrt Rails Partial-Views ) on stackoverflow for the same, I have been lucky on getting things working for me based on my requirement.
Kindly refer to these questions, they might have relevance to your requirement.