Skip to content

Commit

Permalink
daisy
Browse files Browse the repository at this point in the history
  • Loading branch information
YuhangGe authored and YuhangGe committed May 9, 2012
1 parent 2bd8c78 commit 621bb2d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 64 deletions.
12 changes: 2 additions & 10 deletions bug&todo&tip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ tip:
1����ǰfirefox���棬���ڲ��ܽ����ݴ�����а壬��ǰ���õĹ���������û�û���ڳ����ڸ��ƹ�����ճ��ʱճ��ϵͳ���ݣ�����û����ƹ�����ճ�����Ƶ��ڲ����ݡ�

bug:
1. ���һ�еĿ�ʼֱ�������ַ������У���Ӧ�û��С�

2. �����еĶ���ѡ�л������⡣
1������Ƥ����Ƕ��Ⱥ��᲻����ȷ���ơ������ڴ�������ע��˵����

2������Ƥ����Ƕ��Ⱥ��᲻����ȷ���ơ������ڴ�������ע��˵����

4. ��firefox����˫��ʱ���������˫���ڹ���ϻ�ʧЧ����firefox���治�ܴ���doubleclick�¼����������mousedownʱ������λ�øı��������chrome��ie9����û��������⡣������firefox��bug����
2. ��firefox����˫��ʱ���������˫���ڹ���ϻ�ʧЧ����firefox���治�ܴ���doubleclick�¼����������mousedownʱ������λ�øı��������chrome��ie9����û��������⡣������firefox��bug����

todo:

��������

˫������ѡ�У�������bug���������һ�еij��ı��Զ����к�ĵ�һ�����ʻ������⣩


���ֿ�ݼ�


1��doodle �ĸ���ճ��
3. ��firefox����doodleѡ��������ߡ�
2 changes: 1 addition & 1 deletion css/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.sn-caret {
position: absolute;
display: block;
width: 5px;
width: 1px;
background: rgba(0,0,255,0.1);/* transparent; */
left: 0px;
top: 0px;
Expand Down
25 changes: 14 additions & 11 deletions js/editor/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
//this.caret.style.display = "none";
}
},
_deal_leftmouse_down : function(point) {
this.cur_page.select(null);
this.render.paint();
this._moveCaret_xy(point.x, point.y);
_deal_leftmouse_down : function(e, point) {
var nc = this.cur_page._getCaret_xy(point.x,point.y);
if(e.shiftKey) {
this._shift_select(nc.index);
} else {
this._setCaret(nc);
this.cur_page.select(null);
this.render.paint();
}
this.__pre_pos__ = this.caret_pos;
this.__down_pos__ = this.caret_pos;
},
Expand All @@ -37,7 +42,7 @@
//$.log("%d,%d", p.x, p.y);
this._doodle_rightmouse_down(p);
} else {
this._deal_leftmouse_down(p);
this._deal_leftmouse_down(e, p);
}
if( typeof this.canvas.setCapture === 'function')
this.canvas.setCapture(true);
Expand Down Expand Up @@ -280,9 +285,7 @@
},
_cut_handler : function(e) {
this._copy_handler(e);
/**
* to do ...
*/
this._delOrBack();
},
_paste_handler : function(e) {
this.clipboard.getData(e, $.createDelegate(this, this._deal_paste));
Expand Down Expand Up @@ -382,10 +385,10 @@
if(this.cur_mode !== 'handword' && this.cur_mode !== 'readonly')
return;

var p = this._getEventPoint(e, false), ei = this.cur_page._getElementIndex_xy(p.x, p.y),e_arr = this.cur_page.ele_array;
if(ei>0 && e_arr[ei].type !== Daisy._Element.Type.NEWLINE) {
var p = this._getEventPoint(e, false), ei = this.cur_page._getElementIndex_xy(p.x, p.y), e_arr = this.cur_page.ele_array;
if(ei > 0 && e_arr[ei].type !== Daisy._Element.Type.NEWLINE) {
var range = this.wordSeg.getRange(e_arr, ei);

this._setCaret(this.cur_page.selectByIndex(range.from, range.to));
this.render.paint();
}
Expand Down
33 changes: 11 additions & 22 deletions js/editor/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,16 @@
p.index += index_step;
if(para.line_cross !== pre_lc) {
p.line_start += para.line_cross - pre_lc;
for(var j = p.index + 1; j <= p.index + p.length; j++) {
var ele = this.ele_array[j];
var j = p.index + 1, ele = null;
for(; j <= p.index + p.length; j++) {
ele = this.ele_array[j];
ele.bottom += (para.line_cross - pre_lc) * this.editor.render.line_height;
ele.line_at += para.line_cross - pre_lc;
}
/**
* 如果当前段落最后有换行\n也要同时移动。
*/
if((ele = this.ele_array[j])!=null){
ele.bottom += (para.line_cross - pre_lc) * this.editor.render.line_height;
ele.line_at += para.line_cross - pre_lc;
}
Expand All @@ -212,26 +220,7 @@
},
insertLine : function(caret) {
var n_e = new Daisy._NewLineElement(), p_e = null, a_e = null;
//$.log(caret.index)
// if(caret.index >= 0 ) {
// var p = this.para_info[caret.para],p_e = this.ele_array[caret.index];
// $.log(p)
// $.log("%d,%d",p.index + p.length , caret.index)
//
// n_e.left = p_e.left + p_e.width;
// n_e.line_at = p_e.line_at;
// n_e.bottom = p_e.bottom;
// //$.log(n_e)
// if(p.index + p.length === caret.index && this.ele_array.length > caret.index){
// p_e.left = 0;
// //p_e.line_at++;
// //p_e.bottom+=this.editor.line_height;
// n_e.left = 0;
// n_e.bottom+=this.editor.line_height;
// n_e.line_at++;
// }
//
// }

this.ele_array.splice(caret.index + 1, 0, n_e);
var para = this.para_info[caret.para], l_len = caret.para_at + 1, r_len = para.length - l_len;
para.length = l_len;
Expand Down
6 changes: 3 additions & 3 deletions js/editor/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@
},
_paintSelect : function(from, to) {
this.ctx.fillStyle = "rgba(0,255,0,0.2)";
var e_arr = this.page.ele_array, s_e = e_arr[from.index + 1], e_e = e_arr[to.index], s_l = from.line, e_l = to.line;
var c_h = this.font_height, c_w = this.width;

var e_arr = this.page.ele_array, s_e = e_arr[from.index + 1], e_e = e_arr[to.index],
s_l = s_e.line_at, e_l = to.line,
c_h = this.font_height, c_w = this.width;
if(s_l === e_l) {
//$.log(s_e);$.log(e_e);
this.ctx.fillRect(s_e.left, s_e.bottom - c_h + this.baseline_offset, e_e.left - s_e.left + e_e.width, c_h);
Expand Down
84 changes: 69 additions & 15 deletions js/editor/shortkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,82 @@
initShortKey : function() {
this.SHORTKEY_TABLE = {
'ctrl-a' : this._ctrl_a_handler,
'ctrl-top' : this._ctrl_top_handler,
'ctrl-bottom' : this._ctrl_bottom_handler,
'ctrl-up' : this._ctrl_up_handler,
'ctrl-down' : this._ctrl_down_handler,
'ctrl-left' : this._ctrl_left_handler,
'ctrl-right' : this._ctrl_right_handler,
'ctrl-z' : this._undo_handler,
'ctrl-y' : this._redo_handler,
'ctrl-x' : this._ctrl_x_handler,
'left' : this._left_handler,
'right' : this._right_handler,
'top' : this._top_handler,
'bottom' : this._bottom_handler,
'up' : this._up_handler,
'down' : this._down_handler,
'shift-left' : this._shift_left_handler,
'shift-right' : this._shift_right_handler,
'shift-top' : this._shift_top_handler,
'shift-bottom' : this._shift_bottom_handler,
'shift-up' : this._shift_up_handler,
'shift-down' : this._shift_down_handler,
'ctrl-shift-left' : this._ctrl_shift_left_handler,
'ctrl-shift-right' : this._ctrl_shift_right_handler
'ctrl-shift-right' : this._ctrl_shift_right_handler,
'ctrl-home' : this._ctrl_home_handler,
'ctrl-end' : this._ctrl_end_handler,
'shift-home' : this._shift_home_handler,
'shift-end' : this._shift_end_handler,
'ctrl-shift-home' : this._ctrl_shift_home_handler,
'ctrl-shift-end' : this._ctrl_shift_end_handler,
'home' : this._home_handler,
'end' : this._end_handler
};
this.KEY_TABLE = {
36 : 'home',
35 : 'end',
37 : 'left',
39 : 'right',
38 : 'top',
40 : 'bottom'
38 : 'up',
40 : 'down'
}
},
_shift_home_handler : function(){
if(this.caret_pos.para_at<0)
return;
this._shift_select(this.cur_page.para_info[this.caret_pos.para].index);
},
_shift_end_handler : function(){
var p = this.cur_page.para_info[this.caret_pos.para];
if(this.caret_pos.para_at === p.length - 1)
return;
this._shift_select(p.index + p.length);
},
_ctrl_shift_home_handler : function(){
if(this.caret_pos.index<0)
return;
this._shift_select(-1);
},
_ctrl_shift_end_handler : function(){
if(this.caret_pos.index === this.cur_page.ele_array.length - 1)
return;
this._shift_select(this.cur_page.ele_array.length - 1);
},
_home_handler : function(){
this._setCaret(this.cur_page.getCaretByIndex(this.cur_page.para_info[this.caret_pos.para].index));
this.cur_page.select(null);
this.render.paint();
},
_end_handler : function(){
var p = this.cur_page.para_info[this.caret_pos.para];
this._setCaret(this.cur_page.getCaretByIndex(p.index + p.length));
this.cur_page.select(null);
this.render.paint();
},
_ctrl_home_handler : function(){
this._setCaret(this.cur_page.getCaretByIndex(-1));
this.cur_page.select(null);
this.render.paint();
},
_ctrl_end_handler : function(){
this._setCaret(this.cur_page.getCaretByIndex(this.cur_page.ele_array.length-1));
this.cur_page.select(null);
this.render.paint();
},
_undo_handler : function() {
if(this.cur_mode === 'readonly')
return;
Expand Down Expand Up @@ -67,6 +118,9 @@
}
this._setCaret(nc);
this.render.paint();
},
_shift_up_handler : function(){

},
_shift_right_handler : function() {
if(this.caret_pos.index >= this.cur_page.ele_array.length - 1)
Expand Down Expand Up @@ -99,10 +153,10 @@
this.cur_page.select(null);
this.render.paint();
},
_ctrl_top_handler : function() {
_ctrl_up_handler : function() {
this.container.scrollTop -= this.line_height * this.render.scale;
},
_ctrl_bottom_handler : function() {
_ctrl_down_handler : function() {
this.container.scrollTop += this.line_height * this.render.scale;
},
_left_handler : function() {
Expand All @@ -115,18 +169,18 @@
if(!this.__ime_on__)
this.moveCaret("right");
},
_top_handler : function() {
_up_handler : function() {
//向上
this.moveCaret("up");
},
_bottom_handler : function() {
_down_handler : function() {
//向下
this.moveCaret("down");
},
_shortkey_handler : function(e) {
var c_key = (e.ctrlKey ? "ctrl-" : "") + (e.shiftKey ? "shift-" : "") + (this.KEY_TABLE[e.keyCode] == null ? String.fromCharCode(e.keyCode).toLowerCase() : this.KEY_TABLE[e.keyCode]), k_func = this.SHORTKEY_TABLE[c_key];
if( typeof k_func === 'function') {
$.log(c_key);
//$.log(c_key);
k_func.apply(this, []);
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
console.log(msg);
}
function dbl_test(e){
//$.log(e)
$.log(e)
}
function kmp_next(str){
var len = str.length,
Expand All @@ -37,6 +37,9 @@
var dst_next = kmp_next(dst);


}
function deal_keydown(e){
$.log(e.keyCode);
}
$(function(){
$.log(kmp_next("aaacaaad"))
Expand All @@ -48,7 +51,7 @@
<p>Hello World</p>
</div>
<div ondblclick="dbl_test(event);">
<input type="text" value="更重要强大" ondblclick="dbl_test(event);" /><br/>
<textarea type="text" value="更重要强大" onmousedown="dbl_test(event);" onkeydown="deal_keydown(event);" ></textarea><br/>
<input type="button" value="test" id="btn-test" onclick="do_test();"/><br/>
<div>
hello world.4323.3ad_a 葛羽航你好 da ^#@.
Expand Down

0 comments on commit 621bb2d

Please sign in to comment.