mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
css: make CSSStyleSheet.insertRule index optional
This commit is contained in:
@@ -447,6 +447,27 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="CSSStyleSheet_insertRule_default_index">
|
||||
{
|
||||
const style = document.createElement('style');
|
||||
document.head.appendChild(style);
|
||||
const sheet = style.sheet;
|
||||
|
||||
testing.expectEqual(0, sheet.cssRules.length);
|
||||
|
||||
// Call without index, should default to 0
|
||||
sheet.insertRule('.test-default { color: blue; }');
|
||||
testing.expectEqual(1, sheet.cssRules.length);
|
||||
testing.expectEqual('.test-default', sheet.cssRules[0].selectorText);
|
||||
|
||||
// Insert another rule without index, should default to 0 and push the first one to index 1
|
||||
sheet.insertRule('.test-at-0 { color: red; }');
|
||||
testing.expectEqual(2, sheet.cssRules.length);
|
||||
testing.expectEqual('.test-at-0', sheet.cssRules[0].selectorText);
|
||||
testing.expectEqual('.test-default', sheet.cssRules[1].selectorText);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id="CSSStyleSheet_replaceSync">
|
||||
{
|
||||
const sheet = new CSSStyleSheet();
|
||||
|
||||
@@ -55,7 +55,8 @@ pub fn getOwnerRule(self: *const CSSStyleSheet) ?*CSSRule {
|
||||
return self._owner_rule;
|
||||
}
|
||||
|
||||
pub fn insertRule(self: *CSSStyleSheet, rule: []const u8, index: u32, page: *Page) !u32 {
|
||||
pub fn insertRule(self: *CSSStyleSheet, rule: []const u8, maybe_index: ?u32, page: *Page) !u32 {
|
||||
const index = maybe_index orelse 0;
|
||||
var it = Parser.parseStylesheet(rule);
|
||||
const parsed_rule = it.next() orelse return error.SyntaxError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user