avm2: Implement TextField.getLineOffset()
This commit is contained in:
parent
57b371900b
commit
9a6708f4b1
|
@ -148,6 +148,8 @@ package flash.text {
|
||||||
|
|
||||||
public native function getLineText(lineIndex:int):String;
|
public native function getLineText(lineIndex:int):String;
|
||||||
|
|
||||||
|
public native function getLineOffset(lineIndex:int):int;
|
||||||
|
|
||||||
public function getCharBoundaries(charIndex:int):Rectangle {
|
public function getCharBoundaries(charIndex:int):Rectangle {
|
||||||
stub_method("flash.text.TextField", "getCharBoundaries");
|
stub_method("flash.text.TextField", "getCharBoundaries");
|
||||||
return new Rectangle(0, 0, 1, 1);
|
return new Rectangle(0, 0, 1, 1);
|
||||||
|
@ -173,11 +175,6 @@ package flash.text {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLineOffset(lineIndex:int):int {
|
|
||||||
stub_method("flash.text.TextField", "getLineOffset");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParagraphLength(charIndex:int):int {
|
public function getParagraphLength(charIndex:int):int {
|
||||||
stub_method("flash.text.TextField", "getParagraphLength");
|
stub_method("flash.text.TextField", "getParagraphLength");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1191,6 +1191,30 @@ pub fn get_line_text<'gc>(
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_line_offset<'gc>(
|
||||||
|
activation: &mut Activation<'_, 'gc>,
|
||||||
|
this: Object<'gc>,
|
||||||
|
args: &[Value<'gc>],
|
||||||
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
|
let Some(this) = this
|
||||||
|
.as_display_object()
|
||||||
|
.and_then(|this| this.as_edit_text())
|
||||||
|
else {
|
||||||
|
return Ok(Value::Undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
let line_num = args.get_i32(activation, 0)?;
|
||||||
|
if line_num < 0 {
|
||||||
|
return Err(make_error_2006(activation));
|
||||||
|
}
|
||||||
|
|
||||||
|
return if let Some(offset) = this.line_offset(line_num as usize) {
|
||||||
|
Ok(offset.into())
|
||||||
|
} else {
|
||||||
|
Err(make_error_2006(activation))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_bottom_scroll_v<'gc>(
|
pub fn get_bottom_scroll_v<'gc>(
|
||||||
_activation: &mut Activation<'_, 'gc>,
|
_activation: &mut Activation<'_, 'gc>,
|
||||||
this: Object<'gc>,
|
this: Object<'gc>,
|
||||||
|
|
|
@ -1934,6 +1934,13 @@ impl<'gc> EditText<'gc> {
|
||||||
Some(line_text)
|
Some(line_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn line_offset(self, line: usize) -> Option<usize> {
|
||||||
|
let read = self.0.read();
|
||||||
|
let line = read.layout.lines().get(line)?;
|
||||||
|
let first_box = line.boxes_iter().next()?;
|
||||||
|
Some(first_box.start())
|
||||||
|
}
|
||||||
|
|
||||||
fn execute_avm1_asfunction(
|
fn execute_avm1_asfunction(
|
||||||
self,
|
self,
|
||||||
context: &mut UpdateContext<'_, 'gc>,
|
context: &mut UpdateContext<'_, 'gc>,
|
||||||
|
|
Loading…
Reference in New Issue