mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
text: add splitText method
Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
@@ -21,6 +21,13 @@ pub const Text = struct {
|
|||||||
pub fn get_wholeText(self: *parser.Text) []const u8 {
|
pub fn get_wholeText(self: *parser.Text) []const u8 {
|
||||||
return parser.textWholdeText(self);
|
return parser.textWholdeText(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JS methods
|
||||||
|
// ----------
|
||||||
|
|
||||||
|
pub fn _splitText(self: *parser.Text, offset: u32) *parser.Text {
|
||||||
|
return parser.textSplitText(self, offset);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
@@ -36,4 +43,12 @@ pub fn testExecFn(
|
|||||||
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
|
.{ .src = "text.wholeText === 'OK'", .ex = "true" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &get_whole_text);
|
try checkCases(js_env, &get_whole_text);
|
||||||
|
|
||||||
|
var split_text = [_]Case{
|
||||||
|
.{ .src = "text.data = 'OK modified'", .ex = "OK modified" },
|
||||||
|
.{ .src = "let split = text.splitText('OK'.length)", .ex = "undefined" },
|
||||||
|
.{ .src = "split.data === ' modified'", .ex = "true" },
|
||||||
|
.{ .src = "text.data === 'OK'", .ex = "true" },
|
||||||
|
};
|
||||||
|
try checkCases(js_env, &split_text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -513,6 +513,12 @@ pub fn textWholdeText(text: *Text) []const u8 {
|
|||||||
return stringToData(s.?);
|
return stringToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn textSplitText(text: *Text, offset: u32) *Text {
|
||||||
|
var res: ?*Text = undefined;
|
||||||
|
_ = textVtable(text).dom_text_split_text.?(text, offset, &res);
|
||||||
|
return res.?;
|
||||||
|
}
|
||||||
|
|
||||||
// Comment
|
// Comment
|
||||||
pub const Comment = c.dom_comment;
|
pub const Comment = c.dom_comment;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user