A simple way would be to just loop:
var caretPos = 53, // however you get it
start, end
;
for (start = caretPos; start >= 0 && myString[start] != "
"; --start);
for (end = caretPos; end < myString.length && myString[end] != "
"; ++end);
var line = myString.substring(start + 1, end - 1);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…