mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 14:55:07 +00:00
Spreadsheet: Let the cells know their own position in the sheet
This commit is contained in:
parent
13ce24de13
commit
f159d161fa
7 changed files with 227 additions and 22 deletions
|
@ -82,6 +82,7 @@ void SheetGlobalObject::initialize()
|
|||
{
|
||||
GlobalObject::initialize();
|
||||
define_native_function("parse_cell_name", parse_cell_name, 1);
|
||||
define_native_function("current_cell_position", current_cell_position, 0);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
||||
|
@ -106,6 +107,36 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
|||
return object;
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
||||
{
|
||||
if (vm.argument_count() != 0) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, "Expected no arguments to current_cell_position()");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return JS::js_null();
|
||||
|
||||
if (StringView("SheetGlobalObject") != this_object->class_name()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "SheetGlobalObject");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
auto* current_cell = sheet_object->m_sheet.current_evaluated_cell();
|
||||
if (!current_cell)
|
||||
return JS::js_null();
|
||||
|
||||
auto position = current_cell->position();
|
||||
|
||||
auto object = JS::Object::create_empty(global_object);
|
||||
object->put("column", JS::js_string(vm, position.column));
|
||||
object->put("row", JS::Value((unsigned)position.row));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
WorkbookObject::WorkbookObject(Workbook& workbook)
|
||||
: JS::Object(*JS::Object::create_empty(workbook.global_object()))
|
||||
, m_workbook(workbook)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue