CKEditor5 getSelectedElement() - ckeditor

I am working with CKEditor 5 (Baloon Editor) and trying get selected text.
How can I do it?
I tried below code and got NULL:
editor.model.change( writer => {
var selection = editor.model.document.selection;
console.log(selection.getSelectedElement());
} );
Thanks for help.

I guess, selection.getSelectedElement() returns null for text elements. It returns an element object when figure objects selected. You can use
selection.getFirstPosition().parent
or
Array.from(selection.getSelectedBlocks())

Related

How to I focus on an element after it is added in CKEditor?

I am using CKEditor 4.4.1 with CKEDITOR.config.enterMode set to ENTER_P.
I am adding a new paragraph programmatically and then moving the cursor to the new element:
var element = new CKEDITOR.dom.element('p', editor.document);
element.appendBogus();
var range = editor.createRange();
range.setStartAt(referenceNode, CKEDITOR.POSITION_AFTER_END);
range.collapse(true);
editor.editable().insertElement( element, range );
range.moveToElementEditStart( element );
editor.getSelection().selectRanges( [ range ] );
This creates and inserts the element in the correct place. However, for some reason, the cursor is not placed in the newly created element.
Why is this happening?
Because I was using a elements that were not part of CKEditor to trigger the insertion, the CKEditor instance was losing focus.
In addition to the code above, I also had to do editor.focus().

How the elements of scene.children in threeJS can be accessed?

I added some objects to ThreeJS scene (using scene.add(object)). I know the name of object and just want to fetch index of it from scene.children.
I tried to use scene.children.indexOf("objectName") but it returns -1 index. Can anybody suggest what can I do?
Thanks
var object = scene.getObjectByName( "objectName" );
or to recursively search the scene graph
var object = scene.getObjectByName( "objectName", true );
Alternatively, you can search by ID.
var id = scene.getObjectById( 4, true );
three.js r.60
I believe that something that can actually can answer your question is the following code that I use to clean the scene:
while (scene.children.length > 0) {
scene.remove(scene.children[scene.children.length - 1]);
}
this way I don't need to access an element by its name or id. The object are simply fetched from the array with an index, so it's like scene.children[i].
You got an alert text as undefined because you're getting back an object not a value/text. You would need to alert something like scene.getObjectByName( "objectName" ).name or scene.getObjectByName( "objectName" ).id i believe.
The relevant docs: getObjectById, getObjectByName. An important note from getObjectByName:
Note that for most objects the name is an empty string by default. You will have to set it manually to make use of this method.
This could be why you were getting undefined. Also, if you are getting undefined, trying to access .name or .id is going to throw an error. If you were getting an object back you would see something like "[object Object]" in the alert.
Another important note I learned the hard way is that the value you need to pass to getObjectById is object.id, and not object.uuid. Also, object.id is essentially just the index of the object in the children array.
Putting it all together:
// var object = new THREE.Mesh(...) or similar
object.name = 'objectName';
scene.add(object);
var retrievedObject = scene.getObjectById(object.id);
// or
var retrievedObject = scene.getObjectByName('objectName');
alert(retrievedObject.name);

how to get xtragrid focused cell's entity property

I want to get xtragrid focused cell entity property. Because of this :
I'm trying to get, focused cell isnull property, for this i need to get focused cell entityproperty
I tried to get object like (EdmScalarPropertyAttribute)gird.focusedrowvalue, but i got null value exception
How can i do this ?
Thanks
Another way to get the RowHandle of the XtraGridView is this:
int rowHandle = gridView1.GetSelectedRows()[0]
hope it helps, and if you are trying to get the value of the cell you can use the following code
object obj = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[0], gridView1.FocusedColumn.FieldName);

How to check with watin is element "hidden"

Is there a way to verify is element hidden or not - using watin.
I don't want to use Jquery.
Thanks
I managed to work around this by running some jQuery in the browser that reported whether the element was hidden or not:
var jsCommand = String.Format("$('#{0}').is(':visible');", fieldId);
var isVisible = ie.Eval(jsCommand) == "true";
In my experience, there is no concrete way to tell if an individual element is hidden or not in watin.
However, you can recursively check up through the parent tree to see if they contain "display: none" or "visibility: hidden"
This blog gives more detail:
http://blog.coditate.com/2009/07/determining-html-element-visibility.html
You may want to check what method your developers use to hide elements to know if this solution is useful for you.
Not sure if this is any help, but I recently had to use a hidden text field...
public TextField HiddenTitleTextField
{
get
{
return this.Document.TextField(tf => tf.Name == "title" &&
tf.GetAttributeValue("type") == "hidden");
}
}
HTH!

Telerik MVC grid-How to set default row selected

Is it possible to render a Grid with one row selected as default (set the right page number and highlight the row)?
For highlighting, try using the "OnRowDataBound" event
.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
with something like
function onRowDataBound(e) {
var myId = $('#MyId').val();
if (e.dataItem.Id == myId)
e.row.className = 't-state-selected';
}
I'm still trying to figure out how to set the correct initial page number. This bloke might be on to something.
Use the Grid RowAction method, eg:
.RowAction(row => row.Selected = row.DataItem.CustomerCode.Equals(ViewBag.ID))
It is perhaps possible if you iterate in the grid source, locate the row which has to be selected in it, than use a formula to detect on which page will be displayed, and finally change the page index on initial load and select it.

Resources