Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/webapi/html_elements/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,40 @@ impl TextAreaElement {
@{self}.value = @{value};
}
}

/// The offset to the start of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionstart
#[inline]
pub fn selection_start( &self ) -> u32 {
js! (
return @{self}.selectionStart;
).try_into().ok()
}

/// Sets the offset to the start of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionstart
#[inline]
pub fn set_selection_start( &self, value: u32 ) -> Result<(), InvalidStateError> {
js_try! ( @(no_return)
@{self}.selectionStart = @{value};
).unwrap()
}

/// The offset to the end of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionend
#[inline]
pub fn selection_end( &self ) -> u32 {
js! (
return @{self}.selectionEnd;
).try_into().ok()
}

/// Sets the offset to the end of the selection.
// https://html.spec.whatwg.org/#dom-textarea/input-selectionend
#[inline]
pub fn set_selection_end( &self, value: u32 ) -> Result<(), InvalidStateError> {
js_try! ( @(no_return)
@{self}.selectionEnd = @{value};
).unwrap()
}
}