codemirror - get the current word under the cursor - codemirror

Is there a way to get the current text under the cursor?
I don't mean the text of the entire line, but just the single word..
For example, if the cursor is actually in the middle of the word "orange" --> ora|nge,
I need to get the word "orange".
Any way to solve this is much appreciated, thanks in advance

Thanks to Marijn for help, findWordAt is what I was looking for:
editor.on('cursorActivity', function() {
var A1 = editor.getCursor().line;
var A2 = editor.getCursor().ch;
var B1 = editor.findWordAt({line: A1, ch: A2}).anchor.ch;
var B2 = editor.findWordAt({line: A1, ch: A2}).head.ch;
console.log(editor.getRange({line: A1,ch: B1}, {line: A1,ch: B2}));
});

Related

importexcel conditional formatting: How to apply color to entire row

I'm trying to color rows depending on the value of a cell.
eg: if A2 = 1, then color the entire row red ; if A3 = 10 then color entire row orange, etc.
So far I've only managed to get the cell containing the value I'm checking the value of, to have the color applied. ie if A2 =1 then A2 is red but not the entire A row.
This what I'm doing:
$Params = #{
WorkSheet = $xl.Workbook.Worksheets[1]
Range = "A2:A500"
BackgroundColor = "Red"
RuleType = 'Equal'
ConditionValue = "1"
}
Add-ConditionalFormatting #Params
I'm using importexcel
Any help & suggestions gratefully received!

Generate a 2 random color on the same text

I'm new in a flutter. I can't figure out how to generate the 2 random colours on the same Text(). Can anyone help me out? Really appreciate.
String data = "+RM67.80";
var value = data.substring(0,1); // it will get the first character
After that you can check the condition if value == "+" apply green color otherwise apply red.

Highlights on multiple lines LineChart

I am using danielgindi/Charts library.
I have a LineChart with two data sets, I want only one highlight line to highlight both data sets instead of individual highlights for each.
For example, as the picture shows, there are two highlight lines for each line(dataset), but I want only one highlight line can highlight both lines(datasets) and select values similar to this.
Here is the code I have for reference:
let set1 = LineChartDataSet(entries: set1Values, label: "first")
set1.highlightLineWidth = 1
set1.highlightEnabled = true
let set2 = LineChartDataSet(entries: set2Values, label: "second")
set2.highlightLineWidth = 1
set2.highlightEnabled = true
let data = LineChartData(dataSets: [set1, set2])
myChartView.data = data
Thank you for your help.
Why you persist in highlight a line?
I'm not sure but I think you should highlight your chart's container so that checking every line.

Removing x number of characters from the caret position in tinyMCE

I am working on a project where the user can enter a special character and then tab to auto complete the values. This part is mostly working, but I want to be able to delete x number of characters from before the caret position.
E.g. if | is the caret and I have the following text #chr|.
I want to be able to delete 3 characters before the cursor position, e.g. I would just end up with #.
I have found a way to get the current cursor position using the below code, but I haven't been able to find any way of being able to delete x number of characters from that position.
function getCaretPosition()
{
var ed = tinyMCE.get('txtComment'); // get editor instance
var range = ed.selection.getRng().startOffset; // get range
return range;
}
You can do this by creating a Range ending at the current caret position:
var ed = tinyMCE.get("mce_0"); // get editor instance
var editorRange = ed.selection.getRng(); // get range object for the current caret position
var node = editorRange.commonAncestorContainer; // relative node to the selection
range = document.createRange(); // create a new range object for the deletion
range.selectNodeContents(node);
range.setStart(node, editorRange.endOffset - 3); // current caret pos - 3
range.setEnd(node, editorRange.endOffset); // current caret pos
range.deleteContents();
ed.focus(); // brings focus back to the editor
To use the demo, position the caret somewhere in the text and then click the "Remove 3" button at the top to delete the preceding 3 characters.
Note that my demo is simplified and doesn't do any bounds checking.
Demo: http://codepen.io/anon/pen/dWVWYM?editors=0010
Compatibility is IE9+

How do i get the bounding rect of each word in a text (for reading eyetracking)?

For an eye tracking study i need the positions of each word in a text drawn to the window.
I can see how I can get the bounding box of the whole text as a return value using
[nx, ny, textbounds] = DrawFormattedText(win, tstring)
Is there a better way than drawing a whole sentence using this function word by word?
Something like this should do it:
teststr = {'Hello World!' ; 'How are you doing?'}
ystart = 100
xstart = 200
wordgap = 10
for i=1:size(teststr,1)
str=teststr{i};
wordlist = strsplit(str , ' ');
for j=1:size(wordlist)(1)
[nx, ny, textbounds]=DrawFormattedText(win, wordlist{j} ,xstart, ystart);
poslist{j} = textbounds;
xstart=nx+wordgap;
end
end
Not pretty, but it works. You will get problems if you have linebreaks.
EDIT: 2015-07-14: added wordgap suggestion from sven.io