Skip to content

Instantly share code, notes, and snippets.

@advait
Created February 4, 2012 14:23
Show Gist options
  • Save advait/1738160 to your computer and use it in GitHub Desktop.
Save advait/1738160 to your computer and use it in GitHub Desktop.
Row/column fetching!
/**
* Gets font size information about the athens editor and stores it in
* hhwm.athens.
*/
hhwm.reloadAthens = function() {
// Get top and left offset
var athens = $('#athens');
hhwm.athens.topBorder = parseInt(athens.css('border-top-width').replace('px', ''));
hhwm.athens.topPadding = parseInt(athens.css('padding-top').replace('px', ''));
hhwm.athens.topOffset = hhwm.athens.topBorder + hhwm.athens.topPadding;
hhwm.athens.leftBorder = parseInt(athens.css('border-left-width').replace('px', ''));
hhwm.athens.leftPadding = parseInt(athens.css('padding-left').replace('px', ''));
hhwm.athens.leftOffset = hhwm.athens.leftBorder + hhwm.athens.leftPadding;
hhwm.athens.fontSize = parseInt(athens.css('font-size').replace('px', ''));
hhwm.athens.lineHeight = parseInt(athens.css('line-height').replace('px', ''));
// Get character width and height
hhwm.athens.heightDelta = $('#widthMeasurer').height();
hhwm.athens.widthDelta = $('#widthMeasurer').width();
};
/**
* Called when someone clicks on athens
* @param {event} e The jQuery event object.
*/
hhwm.athens.clickHandler = function(e) {
var file = 'test.py'; // TODO(advait): fix this bullshit...
// This is the row/column if we had infinity characters in each direction
var row = Math.floor((e.offsetY - hhwm.athens.topOffset) / hhwm.athens.heightDelta);
var column = Math.round((e.offsetX - hhwm.athens.leftOffset) / hhwm.athens.widthDelta);
console.log(row, column);
// Buffer index
var newIndex = hhwm.buffers.rowColumnToIndex(file, row, column);
// Send message
hhwm.push.moveCursor(file, newIndex);
// Give sparticus focus
$('#sparticus').focus();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment