fix String copy/reference

This commit is contained in:
Karl Seguin
2026-02-27 14:34:20 +08:00
parent 870fd1654d
commit 24491f0dfe
2 changed files with 6 additions and 6 deletions

View File

@@ -270,7 +270,7 @@ pub fn getTextContent(self: *Node, writer: *std.Io.Writer) error{WriteFailed}!vo
try child.getTextContent(writer); try child.getTextContent(writer);
} }
}, },
.cdata => |c| try writer.writeAll(c.getData().str()), .cdata => |c| try writer.writeAll(c._data.str()),
.document => {}, .document => {},
.document_type => {}, .document_type => {},
.attribute => |attr| try writer.writeAll(attr._value.str()), .attribute => |attr| try writer.writeAll(attr._value.str()),
@@ -1028,7 +1028,7 @@ pub const JsApi = struct {
try self.getTextContent(&buf.writer); try self.getTextContent(&buf.writer);
return buf.written(); return buf.written();
}, },
.cdata => |cdata| return cdata.getData().str(), .cdata => |cdata| return cdata._data.str(),
.attribute => |attr| return attr._value.str(), .attribute => |attr| return attr._value.str(),
.document => return null, .document => return null,
.document_type => return null, .document_type => return null,

View File

@@ -388,8 +388,8 @@ pub fn deleteContents(self: *Range, page: *Page) !void {
// Complex case: different containers // Complex case: different containers
// Handle start container - if it's a text node, truncate it // Handle start container - if it's a text node, truncate it
if (self._proto._start_container.is(Node.CData)) |_| { if (self._proto._start_container.is(Node.CData)) |cdata| {
const text_data = self._proto._start_container.getData().str(); const text_data = cdata._data.str();
if (self._proto._start_offset < text_data.len) { if (self._proto._start_offset < text_data.len) {
// Keep only the part before start_offset // Keep only the part before start_offset
const new_text = text_data[0..self._proto._start_offset]; const new_text = text_data[0..self._proto._start_offset];
@@ -398,8 +398,8 @@ pub fn deleteContents(self: *Range, page: *Page) !void {
} }
// Handle end container - if it's a text node, truncate it // Handle end container - if it's a text node, truncate it
if (self._proto._end_container.is(Node.CData)) |_| { if (self._proto._end_container.is(Node.CData)) |cdata| {
const text_data = self._proto._end_container.getData().str(); const text_data = cdata._data.str();
if (self._proto._end_offset < text_data.len) { if (self._proto._end_offset < text_data.len) {
// Keep only the part from end_offset onwards // Keep only the part from end_offset onwards
const new_text = text_data[self._proto._end_offset..]; const new_text = text_data[self._proto._end_offset..];