This commit is contained in:
yumoqing 2025-01-30 11:05:37 +08:00
parent 0a7c9fca0f
commit da3a8f7ed5
3 changed files with 48 additions and 30 deletions

View File

@ -78,9 +78,9 @@ bricks.Cols = class extends bricks.VBox {
data.reverse();
}
for (var i=0;i<data.length;i++){
var d = data[i];
var w = await bricks.widgetBuild(this.record_view, this.main, d);
w.user_data = d;
var r = data[i];
var w = await bricks.widgetBuild(this.record_view, this.main, r);
w.user_data = r;
w.bind('click', this.handle_click.bind(this, w));
w.set_attribute('data-page', page);
if (this.loader.is_max_page(page)){
@ -91,13 +91,16 @@ bricks.Cols = class extends bricks.VBox {
}
if (d.delete_page){
this.delete_page(d.delete_page);
console.log('No.', page, 'added', 'No.', d.delete_page, 'deleted', this.loader.pages , this.loader.cache_pages);
} else {
console.log('No.', page, 'added', this.loader.pages , this.loader.cache_pages);
}
}
delete_page(page){
var items = this.dom_element.querySelectorAll('[data-page="' + page + '"]');
for (var i=0;i<items.length;i++) {
var w = items[i].bricks_widget;
this.container.remove_widget(w);
this.main.remove_widget(w);
}
}
async load_first_page(params){
@ -123,7 +126,7 @@ bricks.Cols = class extends bricks.VBox {
if (d){
this.dataHandle(d);
var total = this.container.dom_element.scrollHeight - this.container.dom_element.clientHeight;
this.container.dom_element.scrollTop = d.pos_rate * total;
// this.container.dom_element.scrollTop = d.pos_rate * total;
} else {
bricks.debug(this.loader, 'load previous page error');
}
@ -167,12 +170,12 @@ bricks.Cols = class extends bricks.VBox {
if (d){
this.dataHandle(d);
var total = this.container.dom_element.scrollHeight - this.container.dom_element.clientHeight;
this.container.dom_element.scrollTop = d.pos_rate * total;
// this.container.dom_element.scrollTop = d.pos_rate * total;
} else {
bricks.debug(this.loader, 'load next page error');
console.log(this.loader, 'load next page error');
}
} catch (e){
bricks.debug('error happened', e);
console.log('error happened', e);
}
this.loading = false;
running.dismiss();

View File

@ -6,7 +6,11 @@ bricks.Layout = class extends bricks.JsWidget {
constructor(options){
super(options);
this._container = true;
this.keyselectable = options.keyselectable || false;
this.children = [];
if (this.use_key_select){
this.enable_key_select();
}
}
set_key_select_items(){
this.key_select_items = this.children;
@ -14,7 +18,6 @@ bricks.Layout = class extends bricks.JsWidget {
enable_key_select(){
this.keyselectable = true;
this.set_key_select_items();
this.selected_children = null;
bricks.app.bind('keydown', this.key_handler.bind(this));
bricks.key_selectable_stack.push(this)
this.select_default_item();
@ -87,25 +90,31 @@ bricks.Layout = class extends bricks.JsWidget {
}
down_level(){
this.set_key_select_items();
for (var i=0;i<this.key_select_items.length;i++){
var w = this.key_select_items[i];
if(w.keyselectable){
w.enable_key_select();
return true;
}
try {
if (w.down_level()){
return true;
}
} catch (e){
;
}
var w = this.selected_item;
if (! w) return;
if (! w.keyselectable){
w = w.find_first_keyselectable_child();
if (! w) return;
}
return false;
bricks.key_selectable_stack.push(this);
this.disable_key_select();
w.enable_key_select();
}
find_first_keyselectable_child(){
for (var i=0;i<this.children;i++){
if (this.children[i].keyselectable){
return this.children[i];
}
var sw = this.children[i].find_first_keyselectable_child();
if (sw) return sw;
}
return null
}
enter_handler(){
if (! this.selected_item) {
return;
}
this.selected_item.dispatch('click');
this.down_level();
}
key_handler(event){
if (!this.is_currkeyselectable()){

View File

@ -12,20 +12,27 @@ bricks.Wterm = class extends bricks.JsWidget {
super(opts);
schedule_once(this.open.bind(this), 0.5);
}
charsize_sizing(){
var cs = bricks.app.charsize;
this.term.setOption('fontSize', cs);
}
async open(){
var term = new Terminal();
var term_options = this.term_options || {};
var term = new Terminal(term_options);
this.term = term;
term.open(this.dom_element);
var ws = new WebSocket(this.opts.ws_url);
bricks.debug('FitAddon=', FitAddon);
this.fitAddon = new FitAddon.FitAddon()
term.loadAddon(this.fitAddon)
// this.fitAddon.fit()
this.fitAddon.fit();
this.charsize_sizing();
this.bind('resize', this.term_resize.bind(this))
ws.onmessage = msg => {
term.write(JSON.parse(msg.data).data);
};
ws.onopen = function(){
term.paste('ls -l\n')
};
term.onData(function(key) {
//Enter
let msg = {
@ -35,13 +42,12 @@ bricks.Wterm = class extends bricks.JsWidget {
ws.send(key);
});
term.focus();
term.paste("ls -l\n");
}
term_resize(){
try {
this.fitAddon.fit();
} catch(e){
bricks.debug('resize error', e);
console.log('resize error', e);
}
}
}